Navigate back to the homepage

how to remove duplicates from array in typescript?

Infinitbility
TypeScript
August 3rd, 2022 · 1 min read
how to remove duplicates from array in typescript?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To remove duplicates from array in typescript, use the new Set() method with it will create new array without dublicate elements.

The Set object lets you store unique values of any type, whether primitive values or object references.

To use new set in array you have to follow below syntax.

1[...new Set(arr)]

Today, I’m going to show you How do I remove duplicates from array in typescript, as above mentioned, I’m going to use the above-mentioned new Set() method to get only unique elements of array.

Let’s start today’s tutorial how do you remove duplicates from array in typescript?

Typescript remove duplicates from array example

Here, we will create an array with some data, and then we will use the new Set() method to remove duplicates elements and store in a different variable.

1let arr1: Array<string> = ["Infinitbility", "aguidehub", "sortoutcode", "sortoutcode", "Infinitbility"];
2let arr2: Array<string> = [...new Set(arr1)];
3console.log(arr2);
4// output: [ 'Infinitbility', 'aguidehub', 'sortoutcode' ]

I hope it helps you, 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 empty an array in javascript?

how to empty an array in javascript?

An example of empty an array in javascript with the step-by-step guide.

August 2nd, 2022 · 1 min read
how to empty an array in react js?

how to empty an array in react js?

An example of an empty array in react js with the step-by-step guide.

August 2nd, 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]