两个数组对象取并集
两个数组对象去并集
arr1中的每一项都是对象,arr2中的每一项也都是对象
const a = [
{_id: 1},
{_id: 2},
{_id: 3},
];
const b = [
{_id: 2},
{_id: 4},
]
解决方法一:
const c = a.filter(x => !b.find(y => y._id === x._id)); // [ { _id: 1 }, { _id: 3} ]
解决方法二:
const c = a.filter(x => b.every(y => y._id !== x._id));