Hi Friends 👋,
Welcome To Infinitbility! ❤️
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)];34console.log(uniqueDomains);
when you run the above code, you will get only three elements in an
let’s see the output.
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.