我有两个像这样简化的数组.
var a = [{ number: 1, name: "A" }, { number: 2, name: "B" }, { number: 3, name: "C" }, { number: 4, name: "D" }, { number: 5, name: "E" }, { number: 6, name: "F" }]; var b = [{ number: 3, name: "C" }, { number: 6, name: "F" }];
我想要的是返回一个数组,其中a过滤b.结果是这样的.
var result = [{ number: 1, name: "A" }, { number: 2, name: "B" }, { number: 4, name: "D" }, { number: 5, name: "E" }];
在堆栈溢出这里看了很多其他解决方案,但无法让它工作.
我可以使用像下划线这样的库.
lodash
通过单线解决方案可以实现.
var a = [{
number: 1,
name: "A"
}, {
number: 2,
name: "B"
}, {
number: 3,
name: "C"
}, {
number: 4,
name: "D"
}, {
number: 5,
name: "E"
}, {
number: 6,
name: "F"
}];
var b = [{
number: 3,
name: "C"
}, {
number: 6,
name: "F"
}];
var result = _.differenceWith(a, b, _.isEqual);
console.log(result)