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 trialThomas Ma
15,199 PointsComplete 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
Rabin Gharti Magar
Front End Web Development Techdegree Graduate 20,928 PointsHey 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 !
William Ma
Front End Web Development Techdegree Graduate 12,958 PointsHi 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.
David Fairhurst
Full Stack JavaScript Techdegree Student 5,081 PointsHi 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].
William Ma
Front End Web Development Techdegree Graduate 12,958 PointsThanks a lot, David, this is a great help.
Tafadzwa Timothy Gakaka
10,978 PointsTafadzwa Timothy Gakaka
10,978 Pointsindeed it helped