給定兩個陣列:(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可能更好 –