Name
Array.lastIndexOf() — search backward through an array
Availability
ECMAScript 5
Synopsis
array.lastIndexOf(value)array.lastIndexOf(value,start)
Arguments
valueThe value to search
arrayfor.startAn optional array index at which to begin the search. If omitted, the search begins with the last element of the array.
Returns
The highest index <= start of
array at which the element is === to value,
or -1 if no such matching element exists.
Description
This method searches backward through successively lower
elements of array for an element that is
equal to value, and returns the index of
the first such element it finds. If start
is specified, it is used as the starting position for the search;
otherwise the search begins at the end of the array. The === operator is used to test equality. The
return value is the index of the first matching element found, or -1
if no match is found.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access