Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在节点控制台中记录深度嵌套的对象_Javascript_Node.js - Fatal编程技术网

Javascript 如何在节点控制台中记录深度嵌套的对象

Javascript 如何在节点控制台中记录深度嵌套的对象,javascript,node.js,Javascript,Node.js,我有一个目标 let a = { name:'Martian', city:'marsTown', luckyNumbers:[1,2,3, { a:'a', b:'b', c:[100,200,300] }] }; 当我在节点控制台中执行console.log(a)时,输出如下 { name: 'Martian', city: 'marsTown', luckyNumbers: [ 1, 2, 3, { a: 'a', b: 'b', c: [Array] }

我有一个目标

let a = {
name:'Martian',
city:'marsTown',
luckyNumbers:[1,2,3,
{
    a:'a',
    b:'b',
    c:[100,200,300]
}]
};
当我在节点控制台中执行
console.log(a)
时,输出如下

{ name: 'Martian',
  city: 'marsTown',
  luckyNumbers: [ 1, 2, 3, { a: 'a', b: 'b', c: [Array] } ] }
{ name: 'Martian',
  city: 'marsTown',
  luckyNumbers: [ 1, 2, 3, { a: 'a', b: 'b', c: [100,200,300] } ] }
我希望输出如下

{ name: 'Martian',
  city: 'marsTown',
  luckyNumbers: [ 1, 2, 3, { a: 'a', b: 'b', c: [Array] } ] }
{ name: 'Martian',
  city: 'marsTown',
  luckyNumbers: [ 1, 2, 3, { a: 'a', b: 'b', c: [100,200,300] } ] }
请帮我怎么做?
我在Ubuntu 18.04工作

我的nodejs版本是:v8.11.4

您可以使用
JSON.stringify()
将整个对象打印为字符串。然后,它将不会打印为
c:[Array]
。相反,它将打印所有属性和值,无论嵌套有多深

console.log(JSON.stringify(a));

a
中存储的不是JSON。JSON是一种基于字符串的数据表示。@t.niese,好的,非常感谢much@HubballiHuli很高兴为JSON提供帮助。stringify()不适用于深层对象使用JSON.stringify(a,未定义,2)获得漂亮的打印结果