You spread the list like this:
const elements = document.getElementsByClassName('modal');
[...elements].forEach((element)=> {
console.log(element)
})
Or in one line like this, this is useful if you are doing multiple loops and do not want to spread every time:
const elements = [...document.getElementsByClassName('modal')];
elements.forEach((element)=> {
console.log(element)
})
Top comments (0)