Recursive function returning undefined | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

25th Mar 2018, 5:15 PM
Akuoma Joshua
Akuoma Joshua - avatar
2 Answers
+ 3
"argument" is not defined in your js
25th Mar 2018, 5:18 PM
Kshitij Dhama
Kshitij Dhama - avatar
+ 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!
25th Mar 2018, 5:23 PM
Akuoma Joshua
Akuoma Joshua - avatar