Array methods
Array.prototype.indexOf()
Finds the first matching present position with strict equality, skipping holes. NaN never matches. Returns -1 when no value matches.
Formal Syntax & Structure
javascript syntaxjavascript
array.indexOf(value, fromIndex)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| value | any | Value to find. |
| fromIndex | Number | Start; default zero. |
Return Value
Number
First matching index or -1.
Working Example
Example Snippetjavascript
const a=[2,7,2];console.log(a.indexOf(2),a.indexOf(2,1));