JavaScript Array lastIndexOf() Method

Javascript array lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.

The lastIndexOf() method searches the array for the specified item, and returns its position.

The JavaScript array lastIndexOf() method is used to search the position of a particular element in a given array. It behaves similar to indexOf() method with a difference that it start searching an element from the last position of an array.

The lastIndexOf() method is case-sensitive. The index position of first character in a string is always start with zero. If an element is not present in a string, it returns -1.


array.lastIndexOf(item, start)

Example -