How to log a deeply nested Object as it is in node console

Viewed 4582

I have an object

let a = {
name:'Martian',
city:'marsTown',
luckyNumbers:[1,2,3,
{
    a:'a',
    b:'b',
    c:[100,200,300]
}]
};

when i do console.log(a) in my node console the output is as follows

{ name: 'Martian',
  city: 'marsTown',
  luckyNumbers: [ 1, 2, 3, { a: 'a', b: 'b', c: [Array] } ] }

I want the output to be as follows

{ name: 'Martian',
  city: 'marsTown',
  luckyNumbers: [ 1, 2, 3, { a: 'a', b: 'b', c: [100,200,300] } ] }

please help me how to do it?
I am working in Ubuntu 18.04
my nodejs version is : v8.11.4

1 Answers

You can use JSON.stringify() to print the entire object as a string. Then, it will not print as c: [Array]. Instead it will print all the properties and values no matter how deeply it is nested.

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