Javascript loops problem

Code :-

   let animals = ['Lions', 'Tigers', 'Bears'];
           for (var i=0; i < animals.length; i++)  {
                console.log(i, animals[i]);
            }

An undefined is printed out at the end.
Why is that?
I can’t figure it out.
THANKS A LOT!!

EDIT :-

SCREENSHOT OF THE OUTPUT :-

image

what do you mean that undefined is printed? can you explain more? do you have a screenshot of the output?

1 Like

image

the code you posted wouldn’t give that, do you have other code? or a special environment?

anyway, i after the loop gets a value of 3, but the loop itself wouldn’t use that value of it as i < animals.length is false in that case

Now for some reason it works!!
THANKS A LOT FOR YOUR TIME!!!

image

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.