arr1 =[{"id":1,"a":2},{"id":2,"c":3},{"id":3,"d":3},{"id":4,"d":3}];
arr2 =[{"id":3,"ed":1111,"vvv":121},{"id":4,"fa":2222},{"id":5,"sa":2222}];
The array formats of arr1 and arr2 are different, but id3 and id4 in arr2 are the same as arr1.
How to realize that after comparing the two arrays, it is found that the IDs are duplicated, and delete the id 3 and id4 in arr1 The entire object?
巴扎黑2017-05-19 10:32:29
var result = arr1.filter(function(element1) {
return !arr2.find(function(element2) {
return element2.id == element1.id;
});
});
console.log(result);