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 trial

JavaScript

Puvanjeet Dhaliwal
Puvanjeet Dhaliwal
18,533 Points

Step 3 in 2_loop.js challenge

In Practice Basic Arrays in JS, (2_loop.js) i used a different method to access each element and log it's index value & value from the answer video. Can anyone advise if there any flaws with what I did? Basically I used destructuring syntax by calling the entries() method on the array to be logged.

INSTRUCTIONS: /* 3. Use a for loop to access each element in the loop. Each time through the loop log a message to the console that looks something like this: Item 0 in the array is 48 When you're done you should have output 10 lines to the console -- one for each element. */

MY ANSWER: for(const [i, v] of myRandomList.entries()) { console.log('Item ' + i + ' in the array is ' + v); }