0👍
From this question:
Using 250R answer:
You need to use
util.inspect()
:const util = require('util') console.log(util.inspect(myObject, {showHidden: false, depth: null, colors: true})) // alternative shortcut console.log(util.inspect(myObject, false, null, true /* enable colors */))
Outputs:
{ a: 'a', b: { c: 'c', d: { e: 'e', f: { g: 'g', h: { i: 'i' } } } } }
Or you can find other ways of doing the same thing on that question page; you can pick whatever you feel comfortable with.
But if I were you, I’d go with:
console.dir(myObject, { depth: null });
because of the following:
- Built-in function from
console
, so no dependencies are needed. - Support colorization.
- No hard coded functions.
0👍
You can do this without additional lib like this:
function logAllParameters(obj, prefix = '') {
for (let key in obj) {
if (typeof obj[key] === 'object') {
logAllParameters(obj[key], prefix + key + '.');
} else {
console.log(prefix + key + ':', obj[key]);
}
}
}
const obj = { a: { b: { c: { d: { e: 1 } } } } };
logAllParameters(obj);
Source:stackexchange.com