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)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3f4ed-2b1c6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3f4ed-2b1c6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?