const arr1 = [1, 2, 3, 56]
const arr2 = [1, 2, 3, 780]
const res = arr2.filter(item1 => !arr1.some(item2 => item2 === item1))
console.log(res); // [780]
arr2 与 arr1相同的元素有 1,2,3 ,res的结果就是 780
const res2 = arr1.filter(item1 => !arr2.some(item2 => item2 === item1))
console.log(res2); // [56]
js去掉两个数组相同的元素
最新推荐文章于 2023-10-31 12:26:43 发布