Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

How to remove duplicates from an array using JavaScript

In this post, you will learn how to remove duplicates from a javascript array. You can remove duplicate values from an array in several ways but here in this post we gonna look at two simple approaches.

Remove duplicates from an array using a Set

Using the Set constructor and the spread syntax:

const names = ["Evan","Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
let uniqueNames = [...new Set(names)]; 
console.log(uniqueNames );

Remove duplicates from an array using Lodash

const names = ["Evan","Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
let uniqueNames = _.uniq(names);
console.log(uniqueNames );

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments