Set has union and difference now
You can stop spreading and filtering to do set operations.
const a = new Set([1, 2, 3]);
const b = new Set([2, 3, 4]);
a.union(b); // {1, 2, 3, 4}
a.intersection(b); // {2, 3}
a.difference(b); // {1}
a.isSubsetOf(b); // falseThey shipped in Node 22 and in current browsers. The method names are the maths names, so the code reads the way you meant it.
javascript