Standard built-ins

Set.prototype.union()

Try the free JavaScript compiler

Return members from receiver then additional argument members, without mutating either. Argument may be set-like (size, has, keys); confirm support in the runtime.

Formal Syntax & Structure

javascript syntaxjavascript
set.union(other)

Parameters & Attributes

NameTypeDescription
otherSet-like objectCollection providing size, has and keys.

Return Value

Set

New result set.

Working Example

Example Snippetjavascript
const a=new Set([1,2]);const b=new Set([2,3]);console.log(JSON.stringify([...a.union(b)]));
JavaScript Reference