Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialStephanie Raymos
3,124 PointsStuck 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
8,686 Pointswhen 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)