Example 1 — Index of the First Match
Get the position of the first number greater than 25.
const numbers = [10, 20, 30, 40, 50];
const index = numbers.findIndex((num) => num > 25);
console.log(index); // 2
console.log(numbers[index]); // 30 How It Works
- Scan from the left. Starts at index
0. - Skip 10 and 20. Both fail
> 25. - Hit 30. First truthy test → return index
2. - Use the index.
numbers[2]reads the matching value.

