jquery - Find object by id in array of javascript objects - Stack Overflow
As you are already using jQuery, you can use the grep function which is intended for searching an array:
var result = $.grep(myArray, function(e){ return e.id == id; });
The result is an array with the items found. If you know that the object is always there and that it only occurs once, you can just use result[0].foo
to get the value. Otherwise you should check the length of the resulting array. Example:
Read full article from jquery - Find object by id in array of javascript objects - Stack Overflow
No comments:
Post a Comment