JavaScript: Use Set to ensure uniqueness of list
To confirm that an array contains unique elements, we can compare the length of that array to the size of the set created from that array.
let numbers = [5, 4, 3, 2, 1, 5]; // array contains duplicates (5)
let numbersSet = new Set(numbers); // Set is created from array using the constructor. Set removes the duplicates silently
numbers.length === numbersSet.size; // prints false
A Set could be created from the array using its constructor. An array could be made from Set using Array.from function. Array checks the membership of an element using includes method, while the Set uses has method for membership.