let arr=['1','3','3','5','6','2','4']
// 数组去重
let arr2=[...new Set(arr)]
console.log(arr2)
// 数组取交集
let arr3=['1','2','5','6','3']
let arr4=[...new Set(arr)].filter(item=> new Set(arr3).has(item))
console.log(arr4)
// 数组并集
let arr5=[...new Set([...arr3,...arr2])]
console.log(arr5)
// 数组差集
let arr6=[...new Set(arr)].filter(item=> !(new Set(arr3).has(item)))
console.log(arr6)
es6-set知识
最新推荐文章于 2024-08-23 09:00:47 发布