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

11

u/the_argus Mar 19 '19

Can also use Array.from(document...).forEach(...)

13

u/BabyLegsDeadpool Mar 19 '19

Or just do [...document.querySelectorAll(...)].forEach(...)

0

u/enHello Mar 19 '19

Or [].slice.call(document.querySelectorAll(...)).map(node => node.foo)

1

u/alinnert Mar 19 '19

Yeah, this is the pre-ES6 version. I used it a lot when I had to. It's just not as clear about what it's doing.

→ More replies (1)