11.6 Arrays of arrays



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?


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

[n, n]
[n, n]



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?


Simple and straightforward :wink:

for(var i = 0, len = arr.length; i < len; i++)

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


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