Array

Array.prototype.findLast

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

Syntax

JavaScript
array.findLast(callbackFn, thisArg?)

Parameters

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

Return Value

The last element that satisfies the testing function, or undefined

Examples

Basic Usage
const numbers = [5, 12, 50, 130, 44];
const found = numbers.findLast(n => n > 45);
console.log(found); // 130
Practical Example
const 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); // 3
Advanced Usage
const arr = [1, 2, 3, 4];
console.log(arr.findLast(n => n % 2 === 0)); // 4

Understanding 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

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.