此处使用了filter和some两种数组筛选过滤的方法进行判断比较
let arrOne = [
{id:1,name:'孙悟空'},
{id:2,name:'猪八戒'},
{id:3,name:'沙悟净'},
{id:4,name:'唐僧'},
{id:5,name:'白骨精'},
{id:4,name:'银角大王'},
{id:4,name:'金角大王'},
]
let arrTwo = [
{id:5,name:'白骨精'},
{id:4,name:'银角大王'},
{id:4,name:'金角大王'},
]
let arrThree = arrOne.filter((e)=>{
return !arrTwo.some((e2)=>{
return e2.id===e.id
})
})
//此处可简写为 :
//let arrThree = arrOne.filter((e)=> !arrTwo.some((e2)=>e2.id===e.id)
console.log(arrThree)
结果展示