Obsessed with React and teaching. I help people become Frontend Developers. Living with my fiancee and Yorkshire Terrier 🐶 in Poland.
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

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!
logo with a rocket of the BigDevSoon application

Level up your Frontend skills

Code real-world projects based on Figma designs.
spread the word
Did you like this post? Share it with the world! 🌐