javascript find return index 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: js find index in list
let myList = ['foo', 'bar', 'qux'];
myList.indexOf('bar');
Example 3: get index of element in array js
const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
console.log(beasts.indexOf('bison'));
console.log(beasts.indexOf('bison', 2));
console.log(beasts.indexOf('giraffe'));
Example 4: js get index of item in array
array.indexOf("item");
Example 5: get the index of object in array
var elementPos = array.map(function(x) {return x.id; }).indexOf(idYourAreLookingFor);
var objectFound = array[elementPos];