Set is a collection containing only unique elements.
Sets are not supported by older browsers such as internet explorer.
Insertion is done via the add
function. Like in the following example:
Output:
Notice that Tokyo
is contained only once, since no duplicates are allowed.
Size is the count of Set's elements. It's accessed via the size
property.
Output:
Certain values can be removed via the delete
function.
Output:
A value can be checked if contained via the has
method.
Output:
It can be iterated via forEach
:
Output: