Access multiDimensional Arrays With Indexe

Tell us what’s happening:

Your code so far

// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];























Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063.

Link to the challenge:

1 Like

how do I complete it

how I’m I supposed to get Mydata = 8

I understood the first part of the answer about the first set of brackets, however the second one I didn’t get it

this is what I have now

var myArray = [[1,2,3], [4,5,6], [7,8,9], [10,11,12], 13, 14];

var myData = [3][8];

I am so sorry I don’t understand. I was doing HTML and CSS for a long time then when I went to JAVASCRIPT I was so confused

thanks @camperextraordinaire

the answer was

var myArray = [[1,2,3], [4,5,6], [7,8,9], [10,11,12], 13,14]

var myData = myArray[2][1]

2 Likes

@LawGaming

Look at the first array dimension
0 = [1,23]
1 = [4,5,6]
2 = [7,8,9]
3 = [10,11,12]
4 = 13
5 = 14

So what you what wanted was in first dimension, element 2
myArray[2][?]

Now looking at the second dimension or the first dimension of the given element
[7,8,9]
0 = 7
1 = 8
2 = 9

Bingo!

myArray[2][1] is the proper index

Good job getting in there and getting it figured out.

-WWC

5 Likes

thanks so much that helped me so much!!!

I like how you broke down the example - helped to visualize it better! I was having trouble with this too, but I understand it now. Thank you! :grinning:

how does that equal to the 8?? i still dont understand.

visual representation:

the arr[2] access the second element of the outer array
arr[2] is an array, which contains the 8, the 8 is the second element, at index 1, so to get the 8 we need to do arr[2][1]