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:

let domains = ['infinitbility', 'aguidehub', 'sortoutcode', 'infinitbility', 'sortoutcode'];
let uniqueDomains = [...new Set(domains)];

console.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 đź‘Ť.