DEV Community

Cover image for Remove duplicate values from an array - Daily JavaScript Tips #4
Dhairya Shah
Dhairya Shah

Posted on • Originally published at codewithsnowbit.hashnode.dev

4 1

Remove duplicate values from an array - Daily JavaScript Tips #4

A clever and easy way to obtain distinct values from an array is by converting the array to a Set

const removeDuplicates = (arr) => [...new Set(arr)];
removeDuplicates ([1, 2, 3, 3, 4, 4, 5, 5, 6, 7, 11, 11, 14, 14, 14]) ;
Enter fullscreen mode Exit fullscreen mode

Thank you for reading, have a nice day!

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay