0
通过使用underscore
或jQuery
是否有更好的方法来检查对象[{id: 1, name: 'some name'}, {id: 2, name: 'other name'}]
的数组是否包含特定的属性值?检查对象数组是否有具有特定值的键的对象
这里是我的方法:
_.filter([{id: 1}, {id: 2}],
function(obj){ return obj.id === 3 }).length === 1; // false
_.filter([{id: 1}, {id: 2}],
function(obj){ return obj.id === 2 }).length === 1; // true
我也是这样做的。找不到更好的方法。 –