JS: Array.prototype.findLastIndex

By Xah Lee. Date: .

(new in JS: ECMAScript 2023)

similar to JS: Array.prototype.findIndex but start from the end.

const isEven = (x) => (x % 2 === 0 ? true : false);

console.log([7, 3, 4, 2].findLastIndex(isEven) === 3);

// if not found, return undefined
console.log([1, 3, 5].findLastIndex(isEven) === -1);

JavaScript. Array Search