In javascript, node.js specifically, I sometimes find myself trying to console.log a variable out while debugging. It works well when objects aren't nested too deep.
return Promise.resolve({plain: 'object'})
.then(console.log);
this prints out
{plan: 'object'}
But with deep nested objects, I have to stringify it to view some of the nested properties.
return Promise.resolve(nestedObj)
.then(function(obj) {
console.log(JSON.stringify(obj, null, 2));
});
Is there a shorter way to simulate the above, that will both call JSON.stringify
and console.log
?
I'm looking for a 1 liner that in effect executes like
.then -> JSON.stringify -> console.log