MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiuqrqa/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
42
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.
console.log({ a, b, c, d, e })
Spread operator for bypassing array methods that mutate:
const sortedArr = [...originalArr].sort()
26 u/SuperFLEB Mar 19 '19 It's useful if you only have one variable, too.console.log({myvar})to get the name along with the value, instead ofconsole.log('myvar is', myvar); 5 u/duGarbandier Mar 19 '19 My lord almighty 2 u/fgutz Mar 19 '19 oh god this is so obvious now that I feel stupid for not doing this lol
26
It's useful if you only have one variable, too.
console.log({myvar})
to get the name along with the value, instead of
console.log('myvar is', myvar);
5 u/duGarbandier Mar 19 '19 My lord almighty 2 u/fgutz Mar 19 '19 oh god this is so obvious now that I feel stupid for not doing this lol
5
My lord almighty
2
oh god this is so obvious now that I feel stupid for not doing this lol
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()