Answers:
使用console.dir()
输出可浏览的对象,你可以点击,而不是通过.toString()
的版本,就像这样:
console.dir(functor);
打印指定对象的JavaScript表示形式。如果要记录的对象是HTML元素,则将打印其DOM表示的属性[1]
[1] https://developers.google.com/web/tools/chrome-devtools/debug/console/console-reference#dir
如果尝试以下操作,可能会得到更好的结果:
console.log(JSON.stringify(functor));
var gandalf = {
"real name": "Gandalf",
"age (est)": 11000,
"race": "Maia",
"haveRetirementPlan": true,
"aliases": [
"Greyhame",
"Stormcrow",
"Mithrandir",
"Gandalf the Grey",
"Gandalf the White"
]
};
//to console log object, we cannot use console.log("Object gandalf: " + gandalf);
console.log("Object gandalf: ");
//this will show object gandalf ONLY in Google Chrome NOT in IE
console.log(gandalf);
//this will show object gandalf IN ALL BROWSERS!
console.log(JSON.stringify(gandalf));
//this will show object gandalf IN ALL BROWSERS! with beautiful indent
console.log(JSON.stringify(gandalf, null, 4));
这对我来说非常合适:
for(a in array)console.log(array[a])
您可以提取在控制台中创建的任何数组,以用于查找/替换清理以及此提取数据的后验使用
for (i in arr) { console.log(i); console.log(arr[i]); }
varName
在Chrome控制台中打印并按Enter即可获得与相同的效果console.dir(varName)
。