How to recursively explore an array in the chrome console

泄露秘密 提交于 2019-12-11 06:46:06

问题


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 :

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

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

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?


回答1:


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

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




回答2:


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, {}]);



回答3:


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

works both in the console and from a script:



来源:https://stackoverflow.com/questions/14537655/how-to-recursively-explore-an-array-in-the-chrome-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!