Home > Tips & Tricks > Get Unique Values From a JavaScript Array

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 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

2 thoughts on “Get Unique Values From a JavaScript Array”

Leave a Comment