Example of set in Javascript ES6

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

Here is an example of iterating through the values of a set in ES6…

example of set

Unlike Map, it can only contain unique values.  You add to a set using “add” instead of “set”.  Note that when we try to add an duplicate value, it will not add to set as evidence by the size property we only still have four items.

Like the map, the set has methods like delete(), clear(), and has()…

more set methods

More ES6 features here.