find index array javascript code example
Example 1: react array find index
const array1 = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element > 13;
console.log(array1.findIndex(isLargeNumber));
Example 2: get the index of object in array
a = [
{prop1:"abc",prop2:"qwe"},
{prop1:"bnmb",prop2:"yutu"},
{prop1:"zxvz",prop2:"qwrq"}];
index = a.findIndex(x => x.prop2 ==="yutu");
console.log(index);
Example 3: 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")
Example 4: js find index in list
let myList = ['foo', 'bar', 'qux'];
myList.indexOf('bar');
Example 5: findindex js
const array = [5, 12, 8, 130, 44];
const index = array.findIndex((item)=> item>10);
console.log(array[index]);
Example 6: js array get index
var fruits = ["Banana", "Orange", "Apple", "Mango"];
return fruits.indexOf("Apple");