Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

javascript - 如何在Node.js的console.log()中获得完整的对象,而不是“ [Object]”?(How can I get the full object in Node.js's console.log(), rather than '[Object]'?)

When debugging using console.log() , how can I get the full object?(使用console.log()调试时,如何获取完整的对象?)

const myObject = { "a":"a", "b":{ "c":"c", "d":{ "e":"e", "f":{ "g":"g", "h":{ "i":"i" } } } } }; console.log(myObject); Outputs:(输出:) { a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } } But I want to also see the content of property f .(但我也想看看属性f的内容。)   ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to use util.inspect() :(您需要使用util.inspect() :)

const util = require('util') console.log(util.inspect(myObject, {showHidden: false, depth: null})) // alternative shortcut console.log(util.inspect(myObject, false, null, true /* enable colors */)) Outputs(产出) { a: 'a', b: { c: 'c', d: { e: 'e', f: { g: 'g', h: { i: 'i' } } } } } See util.inspect() docs .(请参阅util.inspect() docs 。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...