我有这样一个对象:

const myObject = {
   "a":"a",
   "b":{
      "c":"c",
      "d":{
         "e":"e",
         "f":{
            "g":"g",
            "h":{
               "i":"i"
            }
         }
      }
   }
};

但是当我尝试使用console.log(myObject)显示它时,我收到这样的输出:

{ a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }

我怎样才能得到完整的对象,包括属性f的内容?


当前回答

试试这个:

console.dir(myObject,{depth:null})

其他回答

如果你正在寻找一种方法来显示数组中隐藏的项,你必须传递maxArrayLength: Infinity

console.log(util.inspect(value, { maxArrayLength: Infinity }));

我觉得这可能对你有用。

const myObject = { “一”:“一”, " b ": { “c”:“c”, " d ": { “e”:“e”, " f ": { “g”:“g”, " h ": { “我”:“我” } } } } }; console.log (JSON。stringify(myObject, null, '\t'));

如本回答所述:

JSON。Stringify的第三个参数定义了空格插入 打印格式。它可以是字符串或数字(空格数)。

你也可以

console.log(JSON.stringify(myObject, null, 3));

试试这个:

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

输出:

{"a":"a","b":{"c":"c","d":{"e":"e","f":{"g":"g","h":{"i":"i"}}}}}