Array.prototype.findLast()
findLast(callbackFn, thisArg) Returns:
undefined | element · Added in vES2023 · Updated March 13, 2026 · Array Methods array find search es2023
findLast() returns the last element in an array that satisfies a testing function, or undefined if no element matches. It iterates from the end of the array toward the beginning.
Syntax
findLast(callbackFn)
findLast(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 findLast was called on. |
Examples
Basic usage
const nums = [5, 12, 8, 130, 44];
const lastEven = nums.findLast(n => n % 2 === 0);
console.log(lastEven);
// 44
Finding 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 lastActive = users.findLast(u => u.active);
console.log(lastActive);
// { id: 4, name: "Diana", active: true }
When no match is found
const nums = [1, 3, 5, 7];
const result = nums.findLast(n => n > 10);
console.log(result);
// undefined
Common Patterns
Getting the last item satisfying a condition
Use findLast when you need the most recent entry in a time-ordered array:
const events = [
{ type: "click", timestamp: 1700000000 },
{ type: "hover", timestamp: 1700000100 },
{ type: "click", timestamp: 1700000200 },
{ type: "scroll", timestamp: 1700000300 }
];
const lastClick = events.findLast(e => e.type === "click");
console.log(lastClick);
// { type: "click", timestamp: 1700000200 }
See Also
- array::find — finds the first match
- array::filter — returns all matches
- array::at — access elements by index, including negative