find the index of an array object code example

Example 1: findindex js

// 	findIndex(callback fn)  

//	.... return index (when condition meets)
//  .... return -1 (if condition not meets)

const array = [5, 12, 8, 130, 44];

/// it returns the index of number which satisfy the condition true
const index = array.findIndex((item)=> item>10);   //1

/// now we can check what element at that index...
console.log(array[index]); // array[1]

Example 2: get the index of object in array

var elementPos = array.map(function(x) {return x.id; }).indexOf(idYourAreLookingFor);
var objectFound = array[elementPos];