xxxxxxxxxx
// Sample array with duplicates
const array = [1, 2, 3, 1, 4, 2, 5];
// Creating a new set from the array (removes duplicates)
const set = new Set(array);
// Converting the set back to an array (if required)
const uniqueArray = Array.from(set);
console.log(uniqueArray);
xxxxxxxxxx
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
let unique = [new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
xxxxxxxxxx
const arrayWithDuplicateValues = [1, 2, 2, 3, 4, 5, 6, 7, 7, 7, 8, 9];
const uniqueValues = [new Set(arrayWithDuplicateValues)];
console.log(uniqueValues);
//same code with spread operator
const arrayWithDuplicateValues = [1, 2, 2, 3, 4, 5, 6, 7, 7, 7, 8, 9];
const uniqueValues = Array.from(new Set(arrayWithDuplicateValues));
console.log(uniqueValues);