Navigate back to the homepage

How to remove duplicates from array of strings in javascript?

Infinitbility
JavaScript
May 15th, 2022 · 1 min read

Hi Friends 👋,

Welcome To Infinitbility! ❤️

Today, we are going to do how to remove duplicates from an array of strings in javascript, here we will use spread operator syntax to remove duplicate elements.

When we use set() it’s we will create a unique collection, so when we pass any array in set() it will create unique elements of an array which we can also use to remove duplicates from an array.

  • First, convert an array of duplicates to a Set. The new Set will implicitly remove duplicate elements.

  • Then, convert the set back to an array.

The following example uses a Set to remove duplicates from an array:

1let domains = ['infinitbility', 'aguidehub', 'sortoutcode', 'infinitbility', 'sortoutcode'];
2let uniqueDomains = [...new Set(domains)];
3
4console.log(uniqueDomains);

when you run the above code, you will get only three elements in an uniqueDomains array.

let’s see the output.

JavaScript, array remove duplicates example
JavaScript, array remove duplicates example

All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to reverse array without mutating in javascript?

Example of array reverse without mutating in javascript with step by step guide.

May 15th, 2022 · 1 min read

React @mui/x-data-grid search example

React material x-data-grid search functionality examples with a guide to change as per requirement.

May 14th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]