Example 1 — Last Matching Number
Return the last value greater than 30—scanning from the end.
const numbers = [10, 20, 30, 40, 50];
const result = numbers.findLast((n) => n > 30);
console.log(result); // 50 How It Works
- Start at the end. Index
4is checked first. - Test 50.
50 > 30is true. - Return immediately. Result is
50—no need to look at40. - Direction matters. From the start, the first
> 30would be40.

