Skip to content

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 );
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments