共计 253 个字符,预计需要花费 1 分钟才能阅读完成。
// 数组去重
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))));
正文完