Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.