find index js in obj code example
Example 1: using index of on array of objects
arr = [{x: "a", y: 1}, {x: "something", y: 2}]
arr.findIndex(obj => obj.x === "a" && obj.y === 1);
Example 2: find the index of an object in an array
const letters = [{letter: 'a'},{letter: 'b'},{letter: 'c'}]
const index = letters.findIndex((element, index) => {
if (element.letter === 'b') {
return true
}
})
//index is `1`