我有一个对象数组,想要使用 lodash 进行筛选。最终目标是返回数组中任何一个属性值不在另一个数组中的对象。
let inUse = ['1','2'];
let positionData = [{
fieldID: '1',
fieldName: 'Test1'
},
{
fieldID: '2',
fieldName: 'Test2'
},
{
fieldID: '3',
fieldName: 'Test3'
}]
// Only show me position data where the fieldID is not in our inUse array
const original = _.filter(positionData, item => item.fieldID.indexOf(inUse) === -1);
我尝试使用 indexOf
,但我认为在这种情况下我没有正确使用它。
期望结果:
original = {
fieldID: '3',
fieldName: 'Test3'
}