/**
* 取两个数组的交集
*/
const arr1 = [1,2,3,4], arr2 = [3,4,5,6];
let interset = arr2.filter(val => {
return arr1.includes(val)
})
console.log(interset) // [3,4]
/**
* 取两个数组的补集
*/
let complement = arr1.concat(arr2.filter(val => {
return !arr1.includes(val)
}))
console.log(complement) // [1,2,3,4,5,6]
let complement2 = [...new Set(arr1.concat(arr2))]
感谢评论的建议~