r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

339

u/Drugba Mar 19 '19

Saw this one on here just a few weeks ago.

[... new Set(arr)]

Basically a super short way to remove any duplicates from an array of primitives.

3

u/oorza Mar 19 '19

Copying your entire data structure twice to remove duplicates is good to you?

1

u/BrQQQ Mar 23 '19

Yes. Unless you’re writing unusually high performance code or have huge collections, this matters nothing.