How can I display a JavaScript object?
问题 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. 回答1: If you want to print the object for debugging purposes, use the code: 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) Note ' : You can also use a comma in the log