Let’s say you have an array of numbers, which has duplicate items and, you want to clean it up so that it only holds unique value. To remove duplicate items, we can use the
Set data structure. The
Set object allows you to create a collection of unique values and does not permit the insertion of duplicate items.
Let’s look at the following example
array variable holds a lot of duplicate items and only 11 unique items. To filter out duplicate items, we need to pass the
array variable as input to the
That’s it, if we now log the value of the
unique variable we can see it now holds unique values only.
Learn how to convert set to array again.