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