So, to remove duplicates from an array, you can convert it to a set, and then back to an array.
const numbers = [1, 1, 20, 3, 3, 3, 9, 9]; const uniqueNumbers = [...new Set(numbers)]; // -> [1, 20, 3, 9]
Here’s how it works.
new Set(numbers) creates a set from a list of numbers. Creating a set automatically removes all duplicate values. The spread operator
... converts any iterable to an array. This means
[...new Set(numbers)] converts the set right back to an array.