+ 2
Recursive function returning undefined
I have a recursive function for returning nested objects. However when I assign it to a variable and then call the variable it returns undefined. Any idea as to what the problem might be? Thanks! function iterObj(obj){ for (var key in obj){ console.log (key + ":" + obj[key]); if (obj[key] !== null && typeof obj[key] === 'object'){ return iterObj(obj[key]); } } } var solo = iterObj(argument) // nested objects solo // undefined https://code.sololearn.com/W675Ao227f7B/?ref=app
2 Respuestas
+ 3
"argument" is not defined in your js
+ 1
Yeah I know the argument is just a pseudo argument. Right now there's no real argument passed in. I just wanted to know if there was anything wrong with the structure. Thanks!