JS Built-ins
← Set54 / 85
Setunionintermediate

Set union() β€” empty union

πŸ“– 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 with an empty Set returns a copy of the original.

Challenge: Verify union with empty Set.

πŸ’‘ Hints (1)
  • β€’ union() with an empty Set returns a new Set equal to the original