new Set()
Set() constructor is used to create a new set in JavaScript.
new Set()
new Set(iterable)
new
is keyword.Set
is keyword.iterable
is an iterable object like array.
Examples
1. Create an empty Set vowels
.
//create an empty set
const vowels = new Set();
//print set
console.log('Set: ' + [...vowels].join(', '));
2. Create a Set vowels
from an array using Set() constructor.
//create set with elements initialised from array
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
//print set
console.log('Set: ' + [...vowels].join(', '));