ES6 操作数组的并集/交集/差集

来源:互联网 发布:淘宝网溜冰鞋儿童 编辑:程序博客网 时间:2024/05/19 09:15

使用ES6 操作数组

let a = new Set([1, 2, 3]);let b = new Set([3, 5, 2]); // 并集let unionSet = new Set([...a, ...b]);//[1,2,3,5]// 交集let intersectionSet = new Set([...a].filter(x => b.has(x)));// [2,3]// ab差集let differenceABSet = new Set([...a].filter(x => !b.has(x)));