Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在控制台完整地、格式化输出变量 #187

Closed
Dream4ever opened this issue Apr 16, 2022 · 0 comments
Closed

在控制台完整地、格式化输出变量 #187

Dream4ever opened this issue Apr 16, 2022 · 0 comments
Labels
JS Javascript

Comments

@Dream4ever
Copy link
Owner

需求描述

JavaScript 中在用 console.log 输出变量时,如果变量层级比较复杂,那么会输出 { e: 'e', f: [Object] } 这样的变量值。

如果要完整显示变量的每一层内容,并且将输出格式化(pretty-print),就需要进行特定的设置了。

解决过程

Google node.js beautify print nested object content,在 How can I pretty-print JSON using node.js? 中有一个优雅的解决方案:JSON.stringify(someObject, null, 2) 即可实现该需求。

@Dream4ever Dream4ever added the JS Javascript label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS Javascript
Projects
None yet
Development

No branches or pull requests

1 participant