JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Review Array Methods, Iterating and Two-Dimensional Arrays

Stephanie Raymos
Stephanie Raymos
3,122 Points

Stuck on array question

This question is stumping me. I thought just the name of the array would suffice for logging the entire array. What am I missing?

var times = [ 1.22, 1.75, 2.10, 2.55 ]; for (var i=0; i < times.length; i += 1 ) { console.log(times[ ]); }

1 Answer

anthony amaro
anthony amaro
8,220 Points

when you are inside a for loop if you want to log all the elements in the array

var times = [ 1.22, 1.75, 2.10, 2.55 ]; 

for (var i=0; i < times.length; i += 1 ) {
   console.log(times[i]);    //the index to log all the elements in the array
 }

if you want to log the array outside the loop you can just
console.log(times)