Example 1 — Last Matching Index
Find the index of the last even number.
const numbers = [1, 2, 3, 4, 5, 2];
const lastEven = numbers.findLastIndex((n) => n % 2 === 0);
console.log(lastEven); // 5 How It Works
- Build the array. Two even values sit at indexes
1and5. - Scan from the end. The callback tests
n % 2 === 0. - First hit from the end. Index
5is even → return immediately. - No mutation.
numbersstays unchanged; you only get an index.

