Iterate over any item in the array. Every item you visit, check that item's id. If it's a match, return it
If you just want teh codez:
function getId(array, id) {
for (var i = 0, len = array.length; i < len; i++) {
if (array[i].id === id) {
return array[i];
}
}
return null; //nothing found
}
And the same thing using ES5's Array methods:
function getId(array, id) {
var obj = array.filter(function (val) {
return val.id === id;
});
//filter returns an array, and we just want the matching item
return obj[0];
}