Favorites

JavaScript Set.prototype.union() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Set.prototype.union()
JavaScript Set Instance methodThis method is supported by most modern browsers, though support in some browsers is unknown.
Updated 28th November 2026

The union() method returns a new Set containing every value that is in either set.

Description

The union() method returns a new set with the values that are in either set, without duplicates. Neither original set is changed. It's one of the set-algebra methods added to JavaScript in 2024.

A typical use is merging tags, permissions or selected items from two sources without duplicates. To combine more than two sets, chain the calls: a.union(b).union(c).

The argument can be any set-like object, meaning one with a size property and has() and keys() methods, such as another Set or a Map (whose keys are used). Arrays aren't set-like, so wrap them first: new Set(array). The original sets are never changed, and the result keeps the order of the set the method was called on.

Syntax

set.union(other)

Parameters

  • otherAnother Set, or a set-like object.

Return Value

A new Set with the values from both sets.

Example

const a = new Set(['html', 'css']);
const b = new Set(['css', 'js']);
console.log(a.union(b));

Browser Support

The following information will show you the current browser support for the Set.prototype.union() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by most modern browsers, though support in some browsers is unknown.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee