Array.prototype.findLastIndex
Iterates the array in reverse order and returns the index of the first element that satisfies the provided testing function
Syntax
array.findLastIndex(callbackFn, thisArg?)Parameters
| Parameter | Type | Description |
|---|---|---|
| callbackFn | (element, index, array) => boolean | Function to test each element |
| thisArg | any | Value to use as this when executing callbackFn |
Return Value
The index of the last matching element, or -1
Examples
const numbers = [5, 12, 50, 130, 44];
const idx = numbers.findLastIndex(n => n > 45);
console.log(idx); // 3const arr = [1, 2, 3, 4, 3, 2, 1];
console.log(arr.findLastIndex(n => n === 3)); // 4const items = ['a', 'b', 'c', 'b'];
console.log(items.findLastIndex(x => x === 'b')); // 3Understanding 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
Array.prototype.findIndexReturns the index of the first element in an array that satisfies the provided testing function
Array.prototype.findLastIterates the array in reverse order and returns the value of the first element that satisfies the provided testing function
Array.prototype.lastIndexOfReturns the last index at which a given element can be found in the array, or -1 if it is not present, searching backwards
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.