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





Tablets & Mobile






-
Supported Unknown Not supported
Sponsors
Password Manager
PasswordPal stores your passwords and private notes behind encryption that happens in your browser.
Copy Paste List
Copy and paste or download lists in your preferred format, including plain text, PDF, or HTML.
Unicode Characters & Emojis
Search all Unicode characters and emojis plus other tools.
Check Shortened URLs
Expand shortened URLs to view the destination link.
Advertise Here
Advertise your company and products here!