运算
1. 并集(Union)
const setA = new Set([1, 2, 3]);
const setB = new Set([3, 4, 5]);
const union = new Set([...setA, ...setB]);
console.log(union); // 输出: Set { 1, 2, 3, 4, 5 }2. 交集(Intersection)
const intersection = new Set([...setA].filter(x => setB.has(x)));
console.log(intersection); // 输出: Set { 3 }3. 差集(Difference)
4. 对称差(Symmetric Difference)
5. 子集(Subset)
6. 超集(Superset)
7. 例子汇总
总结
Last updated