I am having trouble understanding how this for-in loop showing Undefined values at the end in JavaScript, but in loop the length of first is 3. So, why so many undefined values.
<div class="tab-menu">
<ul>
<li id="first">first item</li>
<li id="second">second item</li>
<li id="third">third item</li>
</ul>
</div>
and the loop -
var first = document.querySelectorAll(".tab-menu ul li");
var f;
for (var i in first) {
f = first[i].innerHTML;
console.log(f);
}
It'll give this in console -
"first item"
"second item"
"third item"
undefined
undefined
undefined
undefined
undefined
undefined