给定两个阵列:(one
和two
)。获得价值不在阵列
one
:包含的值
two
:包含值
我需要从one
获取值其不在two
对象。我试过.filter()
和.indexOf()
,但没有得到理想的结果。
在以下情况下,我希望result
的值为333
。如何实现这一目标?
var one = [111, 222, 333, 444];
var two = [
{ identifier: 111 },
{ identifier: 222 },
{ identifier: 444 }
];
var result = two.filter(function (item) {
console.log(item.identifier, one.indexOf(item.identifier));
});
console.log('result: ', result);
[滤波器阵列不在另一个阵列]的可能的复制(https://stackoverflow.com/questions/33577868/filter-array-not-in-another-array) –
或者https://stackoverflow.com/questions/2963281/javascript-algorithm-to-find-elements-in-array-that-are-not-in-another-array可能更好 –