Acces Multi-Dimensional Arrays With Indexes

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

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/access-multi-dimensional-arrays-with-indexes

There is no need for you to re-assign a new array to myArray varaible. So you can safely remove the last line.

Make sure you are reading the example given carefully… Remember the first doesn’t index start at 1 but it starts at 0.

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

Thanks i figred it out
[2][1] put me on the 8

How did you do it i cant seem to get it i used

added myData which is the same as yours but i cant get the myArray.

Post you code, maybe we can spot the error.

i just got it…All i done was add [2][1]. within the myArray so it can add up but i still need to understand it though…guess i just need practice.

Don’t worry, practice is something that we all need. And even with all the practice, sometimes things slip. Good luck!

1 Like

It’s quite simple: you already know the counting starts from 0 and not 1. All you need to do is just to read the example al-over and compare it with this code.

myData = myArray[2][1];

From the above code, the [2] is to access the box where we have 8 i.e [7,8,9] and since the number 8 is the 2nd but “programmatically” 1st, just access it by [1] so you have the above code.

Give it a like if it helped.

3 Likes

thanks so much, I was understand much better

in the array

arr[3][0][1] equal11

starts counting from array 3. but if it starts counting from 0 in the next array, it means that as it is an array within another? that’s why it starts counting again from 0 and then from the zero array counts 1?

it doesn’t start counting from 1, later

that notation says to get the 4th element of the array, which is a subarray, the first element of the subarray, which is an other subarray and then the second element of this other subarray