Access multiDimensional Arrays With Indexe

Access multiDimensional Arrays With Indexe
0

#1

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:


#2

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


#3

how do I complete it


#4

how I’m I supposed to get Mydata = 8


#5

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.


#6

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


#7

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


#8

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


#9

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.


#10

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


#11

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.

https://www.freecodecamp.org/challenges/store-multiple-values-in-one-variable-using-javascript-arrays

https://www.freecodecamp.org/challenges/nest-one-array-within-another-array

https://www.freecodecamp.org/challenges/access-array-data-with-indexes


#12

thanks @RandellDawson


#13

the answer was

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

var myData = myArray[2][1]


#14

@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


#15

thanks so much that helped me so much!!!