What Is the Difference Between a Set and an Array ?
Problem
In what situation would you use a set object over an array?
Solution
There are some similarities between the two objects. They can both hold on to data of different types. What separates a set is that the values all need to be unique.
The Code
Listing 10-1. Showing the Difference Between Sets and Arrays
var numberSet = new Set();
numberSet.add(1);
numberSet.add(2);
numberSet.add(3);
numberSet.add(3); //does not get added
console.log(numberSet.entries()); //returns SetIterator ...