4 ms·
Or you can console.log(JSON.stringify(x, null, 2));
by thinkingkong 6y ago
Or you can console.log(JSON.stringify(x, null, 2));
- brundolf 6y agoI think you misunderstood the intent of the GP
- matja 6y agoBut this way is easier to reconcile the output, because the values logged shown are what they where at the time of the console.log(), not at the time of expansion (later). Try this in a browser console: x={a:1,b:{c:1}};console.log(x);x.b.c=2; then 'expand' the object, 'c' will be logged as 2, not 1
- brundolf 6y agoThe original commenter was creating the object at log-time, though, which means it wouldn't be shared by anything else. Unless x or y is an object, but in that case the issue is completely tangential to the original suggestion And anyway- JSON.parse(JSON.stringify(x)) would be preferable because you'd still get the browser's rich object exploration
- da39a3ee 6y ago> Unless x or y is an object, but in that case the issue is completely tangential to the original suggestion Of course we have to assume that x and y may be objects!