Array methods

Array.prototype.lastIndexOf()

Try the free JavaScript compiler

Searches present positions backwards using strict equality. Default start is length minus one; an explicitly supplied undefined is converted to zero. Returns -1 if absent.

Formal Syntax & Structure

javascript syntaxjavascript
array.lastIndexOf(value, fromIndex)

Parameters & Attributes

NameTypeDescription
valueanyValue to find.
fromIndexNumberBackward starting position.

Return Value

Number

Last matching index at or before start, or -1.

Working Example

Example Snippetjavascript
const a=[2,7,2];console.log(a.lastIndexOf(2),a.lastIndexOf(2,1));
JavaScript Reference