Full Object Display in Node.js's Console.log()
When working with objects in Node.js, it can be frustrating to receive only a partial representation with console.log(). This representation displays nested objects as "[Object]" rather than their actual contents.
Consider the object below:
const myObject = { "a": "a", "b": { "c": "c", "d": { "e": "e", "f": { "g": "g", "h": { "i": "i" } } } } };
Console.log(myObject) would output:
{ a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }
To display the full object, including nested contents, utilize the util.inspect() method:
const util = require('util') console.log(util.inspect(myObject, {showHidden: false, depth: null, colors: true})) // alternative shortcut console.log(util.inspect(myObject, false, null, true /* enable colors */))
This will output the complete object, including the contents of property f:
{ a: 'a', b: { c: 'c', d: { e: 'e', f: { g: 'g', h: { i: 'i' } } } } }
The above is the detailed content of How Can I Achieve Full Object Display in Node.js's console.log()?. For more information, please follow other related articles on the PHP Chinese website!