CKTIS / JavaScript
Array.prototype.findLastIndex: index of the last match
findLastIndex searches backward and returns the first matching index in that direction, or -1.
Version: ECMAScript 2026 draft; example target: Node.js 24.22.2
Syntax
array.findLastIndex(callbackFn[, thisArg])array.findLastIndex(callbackFn[, thisArg]) starts at length - 1, calls callbackFn(value, index, array) in descending order, and returns the integer index at the first truthy result. With no match it returns -1; it never returns the element value. This cleanly distinguishes failure from a matched undefined.
Length is captured initially. Every index in range is visited and a hole is read as undefined. A lower index changed before its visit is observed, while elements appended beyond the initial length are not examined. A non-callable callback or null/undefined receiver throws TypeError; a callback exception aborts the search. The example returns the last duplicate index and demonstrates -1.
Examples
const values = [4, 7, 4, 9, 4];
console.log(values.findLastIndex(value => value === 4));
console.log(values.findLastIndex(value => value === 10));Result
4 -1