如何显示JavaScript对象? [英] How can I display a JavaScript object?
本文介绍了如何显示JavaScript对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以字符串格式显示JavaScript对象的内容,例如当我们 alert
变量时?
我希望显示对象的格式相同。
解决方案
使用Firefox
如果您想打印对象以进行调试,我建议您安装
注意:您必须 记录对象。例如,这不起作用:
console.log('我的对象:'+ obj)
How do I display the content of a JavaScript object in a string format like when we alert
a variable?
The same formatted way I want to display an object.
解决方案
With Firefox
If you want to print the object for debugging purposes, I suggest instead installing Firebug for Firefox and using the code:
console.log(obj)
With Chrome
var obj = {prop1: 'prop1Value', prop2: 'prop2Value', child: {childProp1: 'childProp1Value'}}
console.log(obj)
will display
Note : you must only log the object. For example this won't work :
console.log('My object : ' + obj)
这篇关于如何显示JavaScript对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文