How to use JavaScript Array findIndex()
Array findIndex
On this page
Array findIndex() Method
Program to use JavaScript Array findIndex() method
let a = [15, 9, 2, 13, 24, 21];
let b = a.findIndex(function (c) {
return c > 18;
});
console.log(b);
Output
4
Steps Description
- Declare three variables a, b and c
- Initialize three variables a, b and c with value of string a = [15, 9, 2, 13, 24, 21], b = a.findIndex(function (c) and c > 18
- Array findIndex() method finds the given statement in array element if any statement element matches then prints its index number
- The value of b variable is displayed with the help of console.log inbuilt function