NodeList to array

OSCC · JavaScript, Browser, Array · Oct 21, 2020

Converts a NodeList to an array.

  • Use spread operator (...) inside new array to convert a NodeList to an array.
const nodeListToArray = nodeList => [...nodeList];
nodeListToArray(document.childNodes); // [ <!DOCTYPE html>, html ]

Recommended snippets

  • Array to HTML list

    JavaScript, Browser

    Converts the given array elements into <li> tags and appends them to the list of the given id.

  • HSL to array

    JavaScript, String

    Converts an hsl() color string to an array of values.

  • RGB to array

    JavaScript, String

    Converts an rgb() color string to an array of values.