get index of value in object javascript code example

Example 1: find index of object in array javascript

a = [
  {prop1:"abc",prop2:"qwe"},
  {prop1:"bnmb",prop2:"yutu"},
  {prop1:"zxvz",prop2:"qwrq"}];
    
index = a.findIndex(x => x.prop2 ==="yutu");

console.log(index);

Example 2: 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 3: js find index of object by value of property and return it's key

const index = Data.findIndex(item => item.name === 'John');