I'm looking at some jQuery code I'm writing at the moment and it just looks plain weird to my C# brain. Is there a better way of doing this?
var idToLookFor = 2;
var myArray = [{id:1},{id:2},{id:3}]
var arrayItem = $.grep(myArray , function (elm) {
return elm.id == idToLookFor;
});
var itemFound = arrayItem[0];
I can understand grep returning an array as rather than it being a find type function its a filter type function so I guess the question should really be is there a function that will only return one item rather than an array?