3

I tried to print a multi-nested object or array to my vscode terminal window and vscode output. My result is a simplified version of what I was trying to print where a generic array/object is shown for anything deeper than 3 layers of nesting. Is there a way to turn off that setting so I can see exactly what is in there? Is there a way to format how my terminal window displays results in general?

let nestedObj1 = [1,{23:{3:4,3:{5:6,7:{3:4,5:{5:1}}}}}]
let nestedArray = [1,2,3,4,[1,2,2,4,2,[3,[4,[5,[1,3,2,3,[1,2,3,4]]]]]]]
console.log(nestedObj1,'\n',nestedArray)
Yin
  • 96
  • 6

1 Answers1

12

It's probably easiest to see nested values in the interactive JS debugger in VSCode. If you can't do that for whatever reason, a trick to show all the deeply nested values would be to console.log the value after using JSON.stringify to transform the entire structure into a string. In your case, you could do:

console.log(JSON.stringify(nestedObj1, null, 2))

The null and 2 arguments control how the JSON is formatted when it is serialized.

jonowles
  • 376
  • 3
  • 7