[javascript] For loop for HTMLCollection elements

You can also do like this:

 let elements = document.getElementsByClassName("classname");
 for(let index in  elements) {
   if(index <= elements.length) {
        console.log(elements[index]);
  }
}

_x000D_
_x000D_
let elements = document.getElementsByClassName("classname");
for (let index in elements) {
  if (index <= elements.length) {
    console.log(elements[index]);
  }
}
_x000D_
<div class="classname"> element 1 </div>
<div class="classname"> element 2 </div>
<div class="classname"> element 3 </div>
_x000D_
_x000D_
_x000D_

or

 let elements = document.getElementsByClassName("classname");
 for(let ele of  elements) {
        console.log(ele);
}

_x000D_
_x000D_
let elements = document.getElementsByClassName("classname");
for (let ele of elements) {
  console.log(ele);
}
_x000D_
<div class="classname"> element 1 </div>
<div class="classname"> element 2 </div>
<div class="classname"> element 3 </div>
<div class="classname"> element 4 </div>
_x000D_
_x000D_
_x000D_