Console.log multidimensional array

So, I created a multidimensional array: (i.e. one with two sets of "coordinates")

var items = [[1,2],[3,4],[5,6]]; 

My site is under construction, and the array when it is loaded and what it contains is constantly changing, so I need to be able to dynamically view the contents of the array while the script is running.

So, I use this:

 console.log(items); 

to display it on the console. This gives me the following result:

alt: Unreadable output of my array

So, is there any other way that I can make the console.logging equivalent of my array, but with a more readable output?

+8
javascript arrays multidimensional-array console
source share
2 answers

You can use javascript console.table

This will display your array as a table, making it more readable and easy to parse.
This is a fairly little-known function, but it is useful when using a multidimensional array.

So, change the code to console.table(items);
It should give you something like this:

  -----------------------
 | (index) |  0 |  1 |
 |  0 |  1 |  2 |
 |  1 |  3 |  4 |
 |  2 |  5 |  6 |
  -----------------------
+17
source share

You can use JSON.stringify()

 console.log(JSON.stringify(items)); 

His conclusion will be similar to

 [[1,2],[3,4],[5,6]] 
+12
source share

All Articles