JavaScript Array indexOf()
JavaScript Array indexOf()
The indexOf() method is used to return the first index of a specified value. It will return -1 if the value is not found. This method starts at a specified index and searches from left to right i.e, from the first element to the last element. However, negative values will count from the last element.
Syntax:-
Its syntax is:- array.indexOf(item, start)
Return:-
Its return is:- index of the first item found else -1.
Further Explanation:-
Parameter | Description |
item | Required. The value to search for. |
start | Optional. Start position. Default is 0. Negative values will start searching from the end of the array. |