Array

Array.prototype.findLastIndex

Iterates the array in reverse order and returns the index of the first element that satisfies the provided testing function

Syntax

JavaScript
array.findLastIndex(callbackFn, thisArg?)

Parameters

ParameterTypeDescription
callbackFn(element, index, array) => booleanFunction to test each element
thisArganyValue to use as this when executing callbackFn

Return Value

The index of the last matching element, or -1

Examples

Basic Usage
const numbers = [5, 12, 50, 130, 44];
const idx = numbers.findLastIndex(n => n > 45);
console.log(idx); // 3
Practical Example
const arr = [1, 2, 3, 4, 3, 2, 1];
console.log(arr.findLastIndex(n => n === 3)); // 4
Advanced Usage
const items = ['a', 'b', 'c', 'b'];
console.log(items.findLastIndex(x => x === 'b')); // 3

Understanding Array.prototype.findLastIndex

The Array.prototype.findLastIndex method in JavaScript iterates the array in reverse order and returns the index of the first element that satisfies the provided testing function. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.

The method signature is array.findLastIndex(callbackFn, thisArg?). It accepts 2 parameters: callbackFn, thisArg. When called, it returns the index of the last matching element, or -1. Understanding when and how to use findLastIndex() helps you write more expressive, readable code.

Common use cases for Array.prototype.findLastIndex include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-findindex, array-findlast, array-lastindexof, enabling you to chain operations together for complex data manipulation pipelines.

Supported in Chrome 97+, Firefox 104+, Safari 15.4+, Edge 97+, and Node.js 18+.

Browser Compatibility

Supported in Chrome 97+, Firefox 104+, Safari 15.4+, Edge 97+, and Node.js 18+.

Related Methods

More Array Methods

Other methods in the Array object

Related Tools

More Array Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.