How to find index of an object by key and value in an javascript array
Posted
by
return1.at
on Stack Overflow
See other posts from Stack Overflow
or by return1.at
Published on 2012-06-29T07:53:52Z
Indexed on
2012/07/05
15:16 UTC
Read the original article
Hit count: 311
JavaScript
|jQuery
Given:
var peoples = [
{ "attr1": "bob", "attr2": "pizza" },
{ "attr1": "john", "attr2": "sushi" },
{ "attr1": "larry", "attr2": "hummus" }
];
Wanted:
Index of object where attr === value
for example attr1 === "john"
or attr2 === "hummus"
Update: Please, read my question carefully, i do not want to find the object via $.inArray nor i want to get the value of a specific object attribute. Please consider this for your answers. Thanks!
© Stack Overflow or respective owner