How to effectively filter out duplicates
Gladly, there is a pretty short one-liner that makes it easy for you to filter out duplicates and get an array only containing unique values.
You can combine the spread operator together with the Set constructor to quickly get all unique values of an array:
const array = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 4]; const unique Values = [...new Set(array)];
There is only one issue with this code: The Set relies on the strict equality comparison (===), so it doesn't work well for objects.
The Whole Tip As An Image
If you like visual content more, or if you want to store it for later, I put all this into one single image for you. I hope you like it!
Before You Leave
I'd love to count you as my ever-growing group of awesome friends!
Interested in reading more such articles from Oliver Jumpertz?
Support the author by donating an amount of your choice.