let arr1 =
[
{ id:'1',name:'zhangsan' },
{ id:'2', name:'lisi' }
]
let arr2 =
[
{ id:'1',name:'zhangsan', age:'15'},
{ id:'2', name:'lisi', age:'16' },
{ id:'3', name:'ani', age:'17'}
]
//取不同的元素(ES6的方法)
let res = arr2.filter(item => !arr1.some(ele=> ele.id === item.id))
console.log('res', res)
//取相同的元素(ES6的方法)
let res2 = arr2.filter(item => arr1.some(ele=> ele.id === item.id))
console.log('res2', res2)
js两个数组对象获取相同和不同的元素对象(ES6)
最新推荐文章于 2024-08-23 09:00:47 发布