This method is like indexOf except that it iterates over elements of array from right to left.
indexOf
array
5.6.0
lastIndexOf([1, 2, 1, 2], 2)// => 3// Search from the `fromIndex`.lastIndexOf([1, 2, 1, 2], 2, 2)// => 1 Copy
lastIndexOf([1, 2, 1, 2], 2)// => 3// Search from the `fromIndex`.lastIndexOf([1, 2, 1, 2], 2, 2)// => 1
The array to inspect.
The value to search for.
The index to search from.
Returns the index of the matched value, else -1.
-1
This method is like
indexOf
except that it iterates over elements ofarray
from right to left.Since
5.6.0
Example