⊗jsSpStInr 37 of 281 menu

Set collections in JavaScript

Set сollections allow you to create arrays without duplicates. Let's see how to work with such collections. First you need to create a collection with the following command:

let set = new Set;

Once the collection has been created, new elements can be added to it using the add method:

let set = new Set; set.add(1); set.add(2); set.add(3);

At the same time, when trying to add an element that already exists in the collection, this element will not be added:

let set = new Set; set.add(1); set.add(2); set.add(3); set.add(3); // will not be added, because it already exists

Create a Set collection. Use the add method to add elements to it. Make sure there are no duplicate elements added.

enru