DEV Community

loading...

Discussion on: Have a Handy JS Snippet You Want to Share?

Collapse
aarohmankad profile image
Aaroh Mankad

Here's a super easy way to remove duplicates from an array (by using the definition of a Set)!


const unique = (arr) => [...new Set(arr)]

// [1, 2, 3, 4, 5]
console.log(unique([1, 1, 2, 3, 4, 5, 5]))

Collapse
nickytonline profile image
Nick Taylor (he/him) Author

Yup that's a good one, although I already have it up top 😺 .

Collapse
aarohmankad profile image
Aaroh Mankad

Oh haha, didn't see that one!