N
N
Nikolai Antonov2016-06-20 15:18:37
JavaScript
Nikolai Antonov, 2016-06-20 15:18:37

Why would return in recursion return undefined?

Why would return in the first example return undefined - https://jsfiddle.net/slavik_210/Lwp0bgr1/1/ ?
And if the result is saved to an external variable, then it works - https://jsfiddle.net/slavik_210/7x95ydjh/

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-06-20
@my-nickname

The result of the recursion must also be returned:

if(list[i].children) {
  return getChildLists(list[i].children, name);
}

P
Peter, 2016-06-20
@petermzg

You look at the console.
There "(index):58 Uncaught ReferenceError: lists is not defined"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question