我有这个对象数组:
[
{
id: 1,
name: 'test 1'
},
{
id: 2,
name: 'test 2'
},
{
id: 3,
name: 'test 3'
},
{
id: 4,
name: 'test 4'
}
]
我有这个 ID 数组:
[1, 3]
如何选择 IDs 数组中存在 id
属性的所有对象?
最佳答案
var ids = [1, 3];
var found = _.where(items, function (item) {
return ids.indexOf(item.id) !== -1;
});
关于javascript - lodash/underscore 通过数组值中的键查找对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30699215/