How can I get the full object in Node.js's console.log(), rather than '[Object]'?

前端 未结 17 2861
一向
一向 2020-11-22 02:59

When debugging using console.log(), how can I get the full object?

const myObject = {
   \"a\":\"a\",
   \"b\":{
      \"c\":\"c\",
      \"d\":         


        
17条回答
  •  囚心锁ツ
    2020-11-22 03:18

    I think this could be useful for you.

    const myObject = {
       "a":"a",
       "b":{
          "c":"c",
          "d":{
             "e":"e",
             "f":{
                "g":"g",
                "h":{
                   "i":"i"
                }
             }
          }
       }
    };
    
    console.log(JSON.stringify(myObject, null, '\t'));

    As mentioned in this answer:

    JSON.stringify's third parameter defines white-space insertion for pretty-printing. It can be a string or a number (number of spaces).

提交回复
热议问题