1

I would like to find a way to explore Array objects in the chrome console (and even other console like firebug), as we can easily do for other objects.

Below is the snippet I entered in the chrome console :

var str = new String("foo"); str;
var bool = new Boolean(true); bool;
["foo", "bar", str, bool, {}];

And the results in the chrome console :
Chrome console explore array snippet

The only way I could find at the moment is kind of a hack :

[["foo", "bar", str, bool, {}]];

Chrome console explore array hack

Is there any option, command or method to just show the inner structure of the array object as it is done by default for other objects?

zoom
  • 1,686
  • 2
  • 16
  • 27

3 Answers3

2

That is what the console.dir() function was built for:

enter image description here

See for more information:

https://developer.mozilla.org/en-US/docs/DOM/console.dir

http://getfirebug.com/logging

https://developers.google.com/chrome-developer-tools/docs/console

ckozl
  • 6,751
  • 3
  • 33
  • 50
1

You can use both console.dir and console.log (depending on the current version):

var str = new String("foo"); str;
var bool = new Boolean(true); bool;

console.dir(["foo", "bar", str, bool, {}]);
console.log(["foo", "bar", str, bool, {}]);
Danilo Valente
  • 11,270
  • 8
  • 53
  • 67
0

Use console.log(["foo", "bar", str, bool, {}]);

works both in the console and from a script: enter image description here

Nicolas Brown
  • 1,546
  • 1
  • 10
  • 17
  • It appears to work only when the array contains an object. I am not able to achieve it with those array for example : `[1,2]` or ["foo","bar"] ;) – zoom Jan 26 '13 at 14:27