Array.prototype.findLastIndex()
findLastIndex(callbackFn, thisArg) Returns:
number · Added in vES2023 · Updated March 13, 2026 · Array Methods array find search es2023
findLastIndex() returns the index of the last element in an array that satisfies a testing function, or -1 if no element matches. It iterates from the end of the array toward the beginning.
Syntax
findLastIndex(callbackFn)
findLastIndex(callbackFn, thisArg)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
callbackFn | function | — | A function to execute for each element. Return true to signal a match. |
thisArg | any | undefined | Optional. Value to use as this when executing callbackFn. |
callbackFn Parameters
| Parameter | Type | Description |
|---|---|---|
element | any | The current element being processed. |
index | number | The index of the current element. |
array | array | The array that findLastIndex was called on. |
Examples
Basic usage
const nums = [5, 12, 8, 130, 44];
const lastEvenIndex = nums.findLastIndex(n => n % 2 === 0);
console.log(lastEvenIndex);
// 4
Finding the index of the last matching object
const users = [
{ id: 1, name: "Alice", active: true },
{ id: 2, name: "Bob", active: false },
{ id: 3, name: "Charlie", active: true },
{ id: 4, name: "Diana", active: true }
];
const lastActiveIndex = users.findLastIndex(u => u.active);
console.log(lastActiveIndex);
// 3
When no match is found
const nums = [1, 3, 5, 7];
const index = nums.findLastIndex(n => n > 10);
console.log(index);
// -1
Common Patterns
Removing the last matching item
Combine findLastIndex with splice to remove the last matching element:
const items = ["a", "b", "c", "b", "d"];
const idx = items.findLastIndex(x => x === "b");
const removed = items.splice(idx, 1);
console.log(removed);
// ["b"]
console.log(items);
// ["a", "c", "b", "d"]
See Also
- array::findIndex — finds the index of the first match
- array::filter — returns all matches
- array::at — access elements by index, including negative