Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.findLast: the last value matching a condition

findLast searches indexes from the end and returns the first value found in that direction, or undefined.

Version: ECMAScript 2026 draft; example target: Node.js 24.22.2

Syntax

array.findLast(callbackFn[, thisArg])

array.findLast(callbackFn[, thisArg]) starts at index length - 1, calls callbackFn(value, index, array) in descending order, and returns the tested value at the first truthy result. It does not return the callback result. With no match it returns undefined, so the result alone cannot distinguish failure from a matched undefined.

Length is captured before the first call. Every index in that range is visited and a hole is read as undefined. A lower index changed before its visit is observed; elements appended beyond the initial length are not examined. A non-callable callback or null/undefined receiver throws TypeError, and callback exceptions propagate. The example walks backward and deliberately matches a hole.

Examples

const values = ["A", , "C", "D"];
const visited = [];
const found = values.findLast((value, index) => { visited.push(`${index}:${value}`); return value === undefined; });
console.log(found);
console.log(visited.join("|"));

Result

undefined
3:D|2:C|1:undefined

Sources