In debugging, I sometimes have an object comprised of a number of key:value pairs, and I need to look at the individual pairs. I have the following code to do that.
for(let [key, value] of Object.entries(params)) {
console.log('(key, value) : (' + key + ', ' + value + ')');
}
But now, I've come across an instance where value is itself an object. All I get in the log for value is [object: Object]
which tells me little.
In an attempt to drill down into value when it is an object, I tried:
for(let [key0, value0] of Object.entries(params)) {
console.log('(key, value) : (' + key0 + ', ' + value0 + ')');
while(typeof value0 === 'object') {
for(let [key1, value1] of Object.entries(value0)) {
console.log('typeof val == obj: (' + key1 + ', ' + value1 + ')');
} // end for-let
} // end while
} // end for-let
But all I managed to do, apparently, was to put the computer in an endless loop.
Perhaps a recursive function is what I need. I know they exist because I've been reading Eloquent JavaScript (Haverbeke, Marijn, 2d ed.), but I'm not (yet?) well enough versed in JavaScript to figure out one on my own.
Can anyone help? I really need to look inside value when it's an object, whether or not by a recursive function.
Thanks so much for reading this far and for your time and effort.
Edit:
I think I see why the endless loop. I do nothing in the while statement group to change the type of value0, so the condition is always true. I never break the while condition. But I still need a solution.