Reputation: 4339
I have this array of objects:
[
{
id: 1,
name: 'test 1'
},
{
id: 2,
name: 'test 2'
},
{
id: 3,
name: 'test 3'
},
{
id: 4,
name: 'test 4'
}
]
I have this array of IDs:
[1, 3]
How can I select all objects whose id
property exists in the IDs array?
Upvotes: 1
Views: 909
Reputation: 6265
var ids = [1, 3];
var found = _.where(items, function (item) {
return ids.indexOf(item.id) !== -1;
});
Upvotes: 2