我如何打印JavaScript对象/变量?

这个问题在这里已经有了答案:

  • 我怎样才能使用JavaScript漂亮地打印JSON? 20个答案

  • 将上面的示例更改为:

    var user = {
      first: 'Jack',
      last: 'Green',
      age: 54
    };
    
    // plain console log
    console.log(JSON.stringify(user, undefined, 2));
    
    // or with interpolation:
    console.log(`User: ${JSON.stringify(user, undefined, 2)}`);
    

    现在我们可以看到漂亮的输出:

    {
      "first": "Jack",
      "last": "Green",
      "age": 54
    }
    
    User: {
      "first": "Jack",
      "last": "Green",
      "age": 54
    }
    
    链接地址: http://www.djcxy.com/p/8451.html

    上一篇: How do i pretty print javascript objects/variables?

    下一篇: JSON.parse and JSON.stringify