Get Unique Values From a JavaScript Array

To get the unique values from a javascript array, we will use a new Set native object. It is very easy and takes less time according to filter method.

We mostly used the filter method to get the unique values from array. It returns all values from the array if the condition matches those values. But in this trick, we will use another way to filter the javascript array to get distinct values.

Let’s see the example.

In the above example, we used a Set to filter the unique values from a javascript array. To know more about Set read here

The above example will return the output like this
[1, 4, 6, 7, "javascript", "js", true, false]

Hope you like the tricks!
Being Tricky 😉


Leave a Reply

Your email address will not be published. Required fields are marked *