JavaScript Set Adding a value to a Set

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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

mySet.add(5);

If the value already exist in the set it will not be added again, as Sets contain unique values.

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

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


Got any JavaScript Question?