DEV Community

Discussion on: πŸš€ Quick tips! 3 ways to get unique values from an array. πŸ’œ

Collapse
 
crs1138 profile image
Honza

It seems that the [... new Set(arr)] is way faster than the other two.

jsbench.me/xnkapa5nxq/1

Collapse
 
nialljoemaher profile image
Niall Maher

That's actually great to know too. Finally, my laziness is paying off. πŸ˜‚

Collapse
 
crs1138 profile image
Honza

HA! Exactly my thought on this topic πŸ˜‚

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Set also reliably keep what is .add() first as well. But I never really tested [...new Set(arr)] on whether the sequence is kept.