DEV Community

Discussion on: Easiest way to convert HTMLCollection into an Array!

Collapse
traekwells profile image
Traek Wells • Edited on

This is a nice write-up. I'd like to add to your first example an even easier way (at least easier by the amount of typing you have to do) and that's Array.from()

var htmlCollection = document.getElementsByClassName('btn');
htmlCollection = Array.from(htmlCollection);
Enter fullscreen mode Exit fullscreen mode

or to make it a bit shorter

var htmlCollection = Array.from(document.getElementsByClassName('btn'))
Enter fullscreen mode Exit fullscreen mode

I use this all the time and it works like a charm.

Collapse
hasnaindev profile image
Muhammad Hasnain Author

Thank you Traek, your solution is neat! 👏