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 JavaScript Arrays Multidimensional Arrays Review JavaScript Arrays

Complete the code below by accessing the values inside the second nested array. The console.log() statement would output

this is for the quiz

3 Answers

Hey Thomas Ma,

The answer to that quiz is:

const coords = [
  [0, 2],
  [1, 3],
  [2, 4]
];

console.log( `x: ${coords[1][0]}, y: ${coords[1][1]}` ); 

Hope this helps !

indeed it helped

Hi Robin, thanks for the answer. could you please explain a little: why x: ${coords[1][0]}, y: ${coords[1][1]}? I review the videos. but still don't understand.

Hi William, because JS uses zero-based array indexing (so the first index position is 0 not 1 in an array).

In the example above with have 3 inner arrays inside the outer array. First inner array position = [0], second [1], third [2].

So to access the 1 value in the second inner (nested) array, we need to access the second nested array [1], and then access the first index position of this nested array [0].

To access the 3 value in the second nested array, we need to access the second nested array [1], and then access the second index position of this nested array [1].

Thanks a lot, David, this is a great help.