Get the index of the object inside an array, matching a condition Get the index of the object inside an array, matching a condition arrays arrays

Get the index of the object inside an array, matching a condition


As of 2016, you're supposed to use Array.findIndex (an ES2015/ES6 standard) for this:

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