11.6 Arrays of arrays


#1


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


I'm sitting here trying to figure out what this means:

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]

How does one do this without writing 2 arrays with the same inputs?


#2

You mean, if input is a number n, you want to output this:

[n, n]
[n, n]

?


#3

Yes. I know with a text string you can use the \ character to log things to the console on separate lines. Is there a way to do it with array data?


#4

Simple and straightforward :wink:

for(var i = 0, len = arr.length; i < len; i++)
    console.log(arr[i]);

Just log each row separately. You know that console.log provides line breaks after each print.


#5

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