Discussion on: How do I use .forEach on DOM Elements?

wilburpowery profile image
Wilbur Powery

I just tested it and it works on Chrome for me.

var elements = Array.from(document.querySelectorAll('p'));

// elements = (3) [p, p, p]

It might not be compatible with many browsers though, as you mentioned.

Thread Thread
maxart2501 profile image
Massimo Artizzu

You don't have to go far - if you have Windows and IE11 installed, that doesn't support either 😉

Thread Thread
notriddle profile image
Michael "notriddle" Howell

The MDN documentation also has an Array.from polyfill: