Convert NodeList to Array quickly

Posted on January 20, 2020

Convert NodeList to Array quickly

Found here and repost in this blog for easier reminder to myself.

var array = [].slice.call(document.querySelectorAll("div"))

This comes in handy from time to time.

Update

There's a more natural and easier-to-remember way to do the same task:

var array = Array.from(document.querySelectorAll("div"))