JS Built-ins
← Set52 / 85
Setunionintermediate

Set union() β€” includes all elements

πŸ“– 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)

The union contains all elements from both Sets, with deduplication.

Challenge: Verify that all unique elements are in the union.

πŸ’‘ Hints (1)
  • β€’ union() combines both Sets and deduplicates values