Sets

Set is a collection containing only unique elements.

Sets are not supported by older browsers such as internet explorer.

Creation

Empty Set

Initial Values

Inserting Data

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

Size is the count of Set's elements. It's accessed via the size property.

Output:

Remove Element

Certain values can be removed via the delete function.

Output:

Contains

A value can be checked if contained via the has method.

Output:

Loop Through

It can be iterated via forEach:

Output: