Array.prototype.findLast
Iterates the array in reverse order and returns the value of the first element that satisfies the provided testing function
Syntax
array.findLast(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 last element that satisfies the testing function, or undefined
Examples
const numbers = [5, 12, 50, 130, 44];
const found = numbers.findLast(n => n > 45);
console.log(found); // 130const data = [
{ id: 1, status: 'active' },
{ id: 2, status: 'inactive' },
{ id: 3, status: 'active' },
];
const last = data.findLast(d => d.status === 'active');
console.log(last?.id); // 3const arr = [1, 2, 3, 4];
console.log(arr.findLast(n => n % 2 === 0)); // 4Understanding Array.prototype.findLast
The Array.prototype.findLast method in JavaScript iterates the array in reverse order and returns the value 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.findLast(callbackFn, thisArg?). It accepts 2 parameters: callbackFn, thisArg. When called, it returns the last element that satisfies the testing function, or undefined. Understanding when and how to use findLast() helps you write more expressive, readable code.
Common use cases for Array.prototype.findLast include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-find, array-findlastindex, array-filter, 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.findReturns the first element in the provided array that satisfies the provided testing function
Array.prototype.findLastIndexIterates the array in reverse order and returns the index of the first element that satisfies the provided testing function
Array.prototype.filterCreates a shallow copy of a portion of a given array, filtered down to just the elements that pass the test implemented by the provided function
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.