Is there any short and neat way of finding an item in the following list with the given searchObject specifications?
var list = [
{ id:1, name: "foo", description: "description 1" },
{ id:2, name: "bar", description: "description 2" },
{ id:3, name: "baz", description: "description 3" },
];
var searchObject = { id: 2, name: "bar" };
The searchObject does NOT necessarily have all the properties of an item in the list. I need the operator between properties to be AND (id==2 && name=="bar"). The following is what I have come up with. Is there anything native in javascript that can do this?
for (var i in list) {
var found = true;
for (var p in searchObject) {
if (list[i][p] !== searchObject[p]) {
found = false;
break;
}
}
if(found) return list[i];
}