how to find a array index value code example

Example 1: react array find index

//The findIndex() method returns the index of the first element 
//in the array that satisfies the provided testing function.
//Otherwise, it returns -1, indicating that no element passed the test.
const array1 = [5, 12, 8, 130, 44];

const isLargeNumber = (element) => element > 13;

console.log(array1.findIndex(isLargeNumber));
// expected output: 3

Example 2: how to find the index of a value in an array in javascript

var list = ["apple","banana","orange"]

var index_of_apple = list.indexOf("apple") // 0

Tags:

Html Example