Set — коллекция для хранения множества значений, причём каждое значение может встречаться лишь один раз. Set отслеживает дубликаты при помощи того же самого алгоритма, что и Map.
Sets are iterable and the for-of loop works as you’d expect:
constset=newSet(["red","green","blue"]);for (constxof set) {console.log(x);}// Output:// red// green// blue
As you can see, Sets preserve iteration order. That is, elements are always iterated over in the order in which they were inserted. The spread operator (...) works with iterables and thus lets you convert a Set to an Array: