TIL how to convert a nodeList into an array
POSTED ON:
TAGS: javascript browser
You can use the spread operator to turn a nodelist into an array!
const el = [...document.querySelectorAll('div')];
console.log(el); // (3) [div, div, div]
el.forEach(item => {
console.log(item);
});
// <div></div>
// <div></div>
// <div></div>
via Chris Bonger's 10 ways to use the spread operator in JavaScript
Related TILs
Tagged: javascript