How to pretty print log output in Chrome DevTools Console?
You could format the data as JSON:
console.log(JSON.stringify({foo:1, bar:2}, null, 4));
{
"foo": 1,
"bar": 2
}
If you are at a breakpoint, you can call JSON.stringify()
directly from the Chrome DevTools console:
> JSON.stringify(anObject, null, 2);
<- "{
"field": "foo",
"array": [
{
"element": 1
},
{
"element": 2
}
],
"object": {
"inner_field": "bar"
}
}"
-----------------------------
>