Array.prototype.lastIndexOf

Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.

Syntax

lastIndexOf(value, fromIndex?);

Parameters

Return value

An index or -1 if the element was not found.

Example

["tea", "coffee", "coffee", "coffee", "juice"].lastIndexOf("coffee")
3
// compare to indexOf:
["tea", "coffee", "coffee", "coffee", "juice"].indexOf("coffee")
1

See also