Adding a value to a set

suggest change

To add a value to a Set, use the .add() method:

mySet.add(5);

If the value already exists in the set, it is not added again, because sets contain unique values. Equality is SameValueZero, so NaN is treated as a duplicate of NaN.

Note that the .add() method returns the set itself, so you can chain add calls together:

mySet.add(1).add(2).add(3);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents