June 5, 2023
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
andc
- Initialize three variables
a, b
andc
with value of stringa = [15, 9, 2, 13, 24, 21], b = a.findIndex(function (c)
andc > 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
by : Suhel Akhtar
Quick Summary:
JavaScript Array findIndex() method