Issue
This Content is from Stack Overflow. Question asked by resetmerlin
const array1 = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element > 13;
console.log(array1.findIndex(isLargeNumber));
// expected output: 3
I don’t get this output.
why 3? there are only 2 of it. Isn’t it?
Solution
The findIndex() method returns the index of the first element in an array that satisfies the provided testing function.
The output is 3 since the first element that is greater than 13 is 130.
5, 12, 8, 130, 44 0 1 2 3 4
The output is the index of the first element that satisfies the condition.
This Question was asked in StackOverflow by resetmerlin and Answered by Gabriel Terry It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.