Sets
Set is a collection of unique values.
Create a new Set
new Set()
creates a new empty Set.
const vowels = new Set();
We can also pass an array of elements as argument to create set with initial values.
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
Add Items to Set
Set.add()
method adds a new element to the set.
const vowels = new Set();
vowels.add('a');
vowels.add('e');
vowels.add('i');
vowels.add('o');
vowels.add('u');
Delete Items from Set
Set.delete()
method removes specified element from the set.
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
vowels.delete('a');
vowels.delete('u');