Access MultiDimensional Arrays With Indexes?

Access MultiDimensional Arrays With Indexes?
0

#1

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

What is the logic about this? I really can’t understand what is goin on here


#2

OK, so you figured out how to work with a one-dimensional array a few challenges back. All that is going on here is you one-dimensional array (the outermost [ ]) which contains elements. The only difference, is some of these elements are arrays too.

To access an element inside an inner array, you must first reference the index position of the inside array first and then reference the index of the inner array item you want to get.

For example, if I want get access the number 2 in myArray, then I first have to reference index of the first element in myArray. The first element is an array at index 0, so I write myArray[0]. Since myArray[0] is referencing the array [1, 2, 3], we now need to reference the 2nd element (the number 2) inside this array. We just add one more set of brackets and put this index where the value 2 is located (index 1) and we get myArray[0][1]. Now we can successfully access the number 2 inside myArray.


#3

Ok so I got it right by saying
// 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[1][2];
var myData = myArray[2] [1];


#4

The above is what gave you the pass test. The first line gets overridden when you re-declare myData as something else.