WTF is an HTMLCollection?
Have you ever written the following code?
const paragraphsToHide = document.getElementsByClassName("p.hide");
paragraphsToHide.forEach(para => para.hidden = true);
// error = paragraphsToHide.forEach is not a function!!!
The reason for your bug is that you have received a HTMLCollection iteratable object and not an array from your DOM Selection method!!
What is an HTMLCollection?
An HTMLCollection is a grouping of HTML Elements, commonly used in manipulating groups of elements on a page.