Set.prototype.add()
The add() method inserts a new element with a specified value in to a Set object, if there isn't an element with the same value already in the Set.
Try it
Syntax
js
add(value)
Parameters
value-
The value of the element to add to the
Setobject.
Return value
The Set object with added value.
Examples
Using the add() method
js
const mySet = new Set();
mySet.add(1);
mySet.add(5).add("some text"); // chainable
console.log(mySet);
// Set [1, 5, "some text"]
Specifications
| Specification |
|---|
| ECMAScript Language Specification # sec-set.prototype.add |
Browser compatibility
BCD tables only load in the browser