Skip to content
Advertisement

For loop only returns last number [closed]

I have made a for loop in order to console log multiple entries in an array. The for loop, however, only returns the last entry in the array, instead of everything from 0 to end of array.

JavaScript

Advertisement

Answer

It will be clearer to you if you ident the code a little bit.

The console.log is outside of the scope, hence, it’s only logging the last assignment before the loop ends.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement