Obsessed with React and teaching. I help people become Frontend Developers. Living with my fiancee and Yorkshire Terrier 🐶 in Poland.
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.
The above is an affiliate link, if you buy the book I'll get a small commission at no extra charge to you.
Home/Pills/ Pill - Remove duplicates in JavaScript/
Home/Pills/Pill - Remove duplicates in.../
Image by Matthew Henry from Unsplash

Remove duplicates in JavaScript

Feb 2, 2021

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 an array argument.
  • The above code needs to be read from the right. We're transforming our duplicates array into a new 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
From time to time, I'll send you messages about new blog posts, knowledge pills, and mentoring promotions. Only valuable information, no spam included. You can unsubscribe at any time.
slack
Let's build a community that will help each other.
spread the word
You don't need to, it's okay...