我有两个数组:
a = [{name:"test3", input:[{val:3}]}, {name:"ss", input:[{val:84}]},{name:"sss", input:[{val:86}]},{name:"test", input:[{val:6}]}, {name:"some", input:[{val:8}]}]
a2 = [{name: "dd", field:3},{name: "dd", field:6}]
现在,我尝试使用`从两个数组中获取唯一值
filter
a.forEach(function(i){
i.input.forEach(function(j){
a2.filter(function(k){return j.val !== k.field;});
});})
然后我想使用:forEach(function(p){p.remove()}); //remove the unique values
所以我将第一个数组中的val
值与第二个数组中的field
值进行比较:
预期结果:
[{name:"ss", input:[{val:84}]},{name:"sss", input:[{val:86}]},{name:"some", input:[{val:8}]}] // these are the ones whose `val` from `a` does not match with the `field` from `a2`
上面的代码没有返回任何内容,你知道会遗漏什么吗?
https://stackoverflow.com/questions/52302294
复制相似问题