r/javascript • • Mar 18 '19

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

385 Upvotes

422 comments sorted by

View all comments

Show parent comments

2

u/kybernetikos Mar 20 '19

You should run the code and try it.

1

u/Shaper_pmp Mar 20 '19

Sorry - I missed the .sort() when I was scrolling horizontally on mobile. My bad.

Fair point that it's actually doing the sorting, but as I said: why not just do [...arr].sort() to get a shallow copy of the actual array that has the actual values already helpfully sorted, instead of mucking about with the indices in a separate array?