Arrays of Arrays. Multidimensional?


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-9Sgpi/1/2?curriculum_id=506324b3a7dffd00020bf661


I did the lesson correctly enough to pass it. But in the explanation part of the instructions it says

"This array is two-dimensional because it has two rows that each contain two items. If you were to put a new line between the two rows, you could log a 2D object—a square—to the console, like so:
[1, 1]
[1, 1]"
Im not sure what it means by put a line between the two rows. What does it mean by this, and how would i do it?

var newArray = [[1,2,3], [1,2,3], [1,2,3]];
console.log(newArray);


#2

@jrobbins0001

When they say you can put a new line between the two rows, they mean if you looped through the array, and logged each index, you would be placing each one on a new line. Using your array as an example:

[1,2,3]
[1,2,3]
[1,2,3]


#4

So you use a new line for each array within the array, like this.

//A new line for each array within the array
var newArray = [[1,2,3],
                [1,2,3],
                [1,2,3]]

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.