r/javascript • • Mar 02 '19

Useful javascript one-liners.

https://medium.com/@smellycode/js-one-liners-8bc0a6af2345?source=friends_link&sk=a9295a05aef9e514e137fca7eeb89cd1
344 Upvotes

96 comments sorted by

View all comments

6

u/Drugba Mar 03 '19

I absolutely love [...new Set(arr)] for removing dupes from an array of primitives. That being said, if I was using it in a shared codebase, I'd be sure to add a comment explaining it as I don't think it's super clear at first glance.

1

u/billymcnilly Mar 03 '19

I found myself writing a comment for this just the other day! But then I decided to use a variable name instead of a comment.

const deduped = [...new Set(allValues)]

Do you think that's descriptive enough?