Using Sets in Javascript To Remove Duplicates

Javascript sets were introduced with ES6 and can be leveraged to quickly remove duplicates from an array. Since a set only allows unique values when you instantiate (create) a new set it automatically removes duplicates from an array. This can give you a quick one liner to the age old question how to remove duplicates from an array. Sets can be useful in general if you need a unique collection of items.

set-code

This is a guide article about sets and this Stack Overflow answer has some good info as well. Check our codepen to experiment.

Read more about Sets on Mozilla

Instagram Post