The es6 method Filter drops the items with the same id value of the objects in the two arrays.

const arr1=[{id:1,name:""},{id:2,name:""}]
const arr2=[{id:1,name:""},{id:3,name:""}]

the es6 method Filter drops the same items of id and arr1 id in arr2

Mar.11,2021

I'll share it myself

 let arr1=[{id:1,name:''},{id:2,name:''}]
 let arr2=[{id:1,name:''},{id:3,name:''},{id:44,name:''},{id:45,name:''},]

  let add=arr2.filter(item=>!arr1.some(ele=>ele.id===item.id))
  console.log(add)

const arr1 = [{ id: 1, name: '' }, { id: 2, name: '' }];
const arr2 = [{ id: 1, name: '' }, { id: 3, name: '' }];
// arr1id
let arr1Ids = arr1.map(item => item.id);
// arr2arr1id
const result = arr2.filter(item => !arr1Ids.includes(item.id));
console.log(result); // [{id: 3, name: ""}];

for reference

    let arr3 = arr2.filter((item1) => {
      return arr1.findIndex((item2) => {
        return item2.id == item1.id
      }) == -1
    })
    console.log(arr3)
Menu