Obsessed with React and teaching. I help people become Frontend Developers. Living with my fiancee and Yorkshire Terrier 🐶 in Poland.
Discover Mentorship
Discover Mentorship
The above is an affiliate link, if you buy the book I'll get a small commission at no extra charge to you.
Obsessed with React and teaching. I help people become Frontend Developers. Living with my fiancee and Yorkshire Terrier 🐶 in Poland.
Image by Matthew Henry from Unsplash
DESCRIPTION
Clones might take over the world, we - as JavaScript guardians need to learn how to remove duplicates from an array.
Preview
removeDuplicates one-liner
JavaScript
Summary
- We created
removeDuplicates
function which accepts anarray
argument. - The above code needs to be read from the right. We're transforming our duplicates
array
into anew Set
. Set is a specific data structure that accepts only unique values. - After that, we're getting back to an array, using the Rest spread operator with array syntax,
[...]
. - One-liner, clean and modern, one more time: duplicates array -> new Set(array) = only unique values -> [...] spread into an array again = no more clones!
THE GUIDE TO BEAT FRONTEND INTERVIEW
slack
Let's build a community that will help each other.