JS Built-ins
← Set55 / 85
Setunionintermediate

Set union() β€” originals unchanged

πŸ“– Usage Example
const a = new Set([1, 2])
const b = new Set([2, 3])
const all = a.union(b)
console.log([...all]) // β†’ [1, 2, 3]

Use Set.union() to combine two sets into a new set containing all unique values.

Set.prototype.union() (ES2025)

union() returns a new Set and does not modify the originals.

Challenge: Verify that original Sets are unchanged after union().

πŸ’‘ Hints (1)
  • β€’ union() returns a new Set; neither original is modified