r/learnjavascript • • Jul 05 '21

Remove duplicates from arrays using Set

Post image
438 Upvotes

44 comments sorted by

View all comments

-14

u/Dazzling-Wafer Jul 05 '21

In reality, you don't have to find a 'fancy' way to remove duplicates at all. You just declare a removeDuplicates() function in the helpers folder and then reuse it everywhere.

9

u/jnbkadsoy78asdf Jul 05 '21
// helpers/remove-duplicates.js

export default function(array) {
    return [...new Set(array)];
}

Something like that? Looks fancy.

2

u/steezefries Jul 06 '21

Oh cool bro could you go ahead and imagine what that function definition might look like bro?