Skip to content

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

@Dream4ever

Description

@Dream4ever

需求描述

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) 即可实现该需求。

Metadata

Metadata

Assignees

No one assigned

    Labels

    JSJavascript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions