Hello, folks!
1) Remove duplicates from an array using a Set
A Set is a collection of unique values. To remove duplicates from an array:
- First, convert an array of duplicates to a Set. The new Set will implicitly remove duplicate elements.
- Then, convert the set back to an array.
- The following example uses a Set to remove duplicates from an array:
let dublicates = ['A', 'A', 'A', 'B', 'C', 'C'];
let uniqueChars = [...new Set(dublicates)];
Output:
[ 'A', 'B', 'C' ]
If you like my work and want to support me to work hard, please donate via:
Revolut website payment or use the QR code above.
Thanks a bunch for supporting me! It means a LOT 😍
Top comments (0)