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

You did not ask a question. Please tell us what you do not understand.

1 Like

how do I complete it

how I’m I supposed to get Mydata = 8

myArray is an array of arrays. First question to answer is what index of myArray contains the sub array with the 8 in it? That index will go in the first set of brackets. Next question is what index in the referenced sub array contains the actual value 8? This index will go in the second set of brackets.

In the example the challenge shows, they did the same thing, but they had one extra sub array which had to be referenced.


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

The referenced sub array is the sub array whose index you put in the first set of brackets.

1 Like

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];

Arrays are zero-indexed, so the 1st element has an index of 0, 2nd element has an index of 1, and so on. You do not have the correct index for the sub array with the value 8 in it. You are referencing the 4th element instead of the 3rd. Then, you put an 8 in the second set of brackets, but the sub array [ 7,8,9] only has 3 elements with indexes 0, 1, 2.

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

I suggest going back to the following challenges and Resetting the code, so you can learn the basics of one-dimensional arrays before moving on to multi-dimensional arrays which this challenge has.


thanks @RandellDawson

the answer was

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

var myData = myArray[2][1]



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

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


myArray[2][1] is the proper index

Good job getting in there and getting it figured out.



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]