Array Itteration and console.log

Hi Everyone. just doing some practice and i am running into some issues with console.log

var numbers =
for(var i =0; i<=9; i++){

My array prints out 0-9 in this loop, but when I try to console.log the last item in this array, item 10, it says undefined. Not to sure where the problem is.


Arrays are zero-indexed, which means the index starts at 0. The last index in an array will be one less than the number of elements in the array. Your numbers array has 10 elements, so the last index is 9. When you try to reference an index of 10, it does not exist, so you get undefined.

1 Like

Thanks for the help randell! much appreciated