// 数组去重
let arr = [1, 1, 2, 3];
let unique = [... new Set(arr)];
let a = new Set([1, 2, 3]);
let b = new Set([4, 3, 2]);
// 并集
let union = [...new Set([...a, ...b])];
// 交集
let intersect = [...new Set([...a].filter(x => b.has(x)))];
// 差集
let difference = Array.from(new Set([...a].filter(x => !b.has(x))));
es6 Set的几种使用场景
最新推荐文章于 2022-08-07 09:53:19 发布