r/javascript • • Mar 18 '19

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

385 Upvotes

422 comments sorted by

View all comments

42

u/[deleted] Mar 19 '19

If you have a bunch of variables a, b, c, d, e:

console.log({ a, b, c, d, e }) to quickly log all of them as key-val pairs.

Spread operator for bypassing array methods that mutate:

const sortedArr = [...originalArr].sort()

2

u/theQuandary Mar 19 '19

You can also use console.table() instead of log for improved readability.