Favorites

JavaScript Set.prototype.add() 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.add()
JavaScript Set Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The add() method adds a value to a Set, unless it is already there.

Description

The add() method inserts a value into the set if it isn't already present; adding a duplicate does nothing. It returns the set, so calls can be chained.

The iteration order of a set is the order in which values were first added, and adding an existing value doesn't move it.

Values are compared with the SameValueZero algorithm, so NaN matches NaN, but two separate objects with the same contents are different values.

Syntax

set.add(value)

Parameters

  • valueThe value to add.

Return Value

The same Set, so calls can be chained.

Example

const s = new Set();
s.add('a').add('b').add('a');
console.log(s, s.size);

Browser Support

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

This method is supported by all modern browsers.

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