这可能已经回答了,但我确实搜索过。
在 .js 文件中:
console.log({
a: 1,
b: { c: 1},
d: [{e:1},{f:1}],
g: [{h:[1,2,3]}]
});
这是实际打印的内容:
{ a: 1,
b: { c: 1 },
d: [ { e: 1 }, { f: 1 } ],
g: [ { h: [Object] } ]
}
注意'h'值,我可以打印吗?
这可能已经回答了,但我确实搜索过。
在 .js 文件中:
console.log({
a: 1,
b: { c: 1},
d: [{e:1},{f:1}],
g: [{h:[1,2,3]}]
});
这是实际打印的内容:
{ a: 1,
b: { c: 1 },
d: [ { e: 1 }, { f: 1 } ],
g: [ { h: [Object] } ]
}
注意'h'值,我可以打印吗?
它允许您指定打印深度:
The default is to only recurse twice. To make it recurse indefinitely, pass in null for depth.
要使用它,您可以致电console.log(util.inspect(yourObj, true, null));
console.dir()说它使用util.inspect()
,但不显示修改inspect()
调用的参数,所以它也可能只会递归两次。
你可以用for loop
它来迭代它..
var obj = {
a: 1,
b: {c: 1},
d: [{e: 1}, { f: 1}],
g: [{ h: [1, 2, 3]}]
};
var data = obj.g[0].h ;
for(var i =0; i <data.length ; i++){
console.log(data[i])
}
我已经用JSON.stringify()
它来实现了,可以用参数来确定格式。
如上所述,util.inspect()
也有效。