Codementor Events

JS - Quick ones - Removing Duplicates

Published Aug 31, 2018
JS - Quick ones - Removing Duplicates

How do you remove duplicates from an array?

During ES5 era, you'd either have to de-duplicate using an object (using it like as hashmap), or sort the array and iterate over to remove duplicates in-place or use lodash uniq().

But with Set() and spread operator it has become as easy as:

const arrayWithoutDuplicates = [ ...new Set(originalArray) ];

How easy!

BTW, it also works for an array of objects. How cool is that?

Discover and read more posts from Munawwar Firoz
get started