Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  182] [ 4]  / answers: 1 / hits: 25877  / 9 Years ago, sun, may 31, 2015, 12:00:00

So I have created a multi-dimensional array: (i.e. one with two sets of 'coordinates')



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


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



So, I use this:



console.log(items);


to output it to the console. This gives me the following output:



alt:



So, is there any other way in which I can do the equivalent of console.logging my array, but with more readable output?


More From » arrays

 Answers
12

You can use javascript's console.table



This will display your array in table form, making it much more readable and easy to analyse

It is quite a little known feature, however useful when you have a multi-dimentional array.



So, change your code to console.table(items);

It should give you something like this:




-----------------------
|(index)| 0 | 1 |
| 0 | 1 | 2 |
| 1 | 3 | 4 |
| 2 | 5 | 6 |
-----------------------

[#66393] Thursday, May 28, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dusty

Total Points: 739
Total Questions: 97
Total Answers: 85

Location: Angola
Member since Wed, Apr 13, 2022
2 Years ago
;