Name

Array.lastIndexOf() — search backward through an array

Availability

ECMAScript 5

Synopsis

array.lastIndexOf(value)
array.lastIndexOf(value, start)

Arguments

value

The value to search array for.

start

An 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.

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.