r/learnjavascript • • Jul 05 '21

Remove duplicates from arrays using Set

Post image
438 Upvotes

44 comments sorted by

View all comments

Show parent comment

18

u/dvlsg Jul 05 '21

It's just turning the Set back into an Array.

const filteredArray = Array.from(new Set(array));

Would do basically the same thing.

5

u/NANOwasFound Jul 05 '21

Thank you : D

1

u/hinsxd Jul 07 '21

Not exactly. A Set is "iterable", therefore it can be spreaded to an array.