// [1, 2, 3, 6, 7] [8, 2, 4, 6, 9] 如何取交集[2,6]
// 如何取并集[1, 8, 2, 3, 4, 6, 7, 9] // 去重
const arr1 = [1, 2, 3, 6, 7]
const arr2 = [8, 2, 4, 6, 9]
const arrN1 = []
const arrN2 = [...arr1, ...arr2]
arr1.forEach(i => {
arr2.forEach(j => {
if (i === j) {
arrN1.push(i)
}
})
})
console.log(arrN1)
console.log(Array.from(new Set(arrN2)))
2021.05.14 数组取并集 && 交集【面经】
最新推荐文章于 2021-05-23 02:11:04 发布