title: Return a value from loop in recursive function
body: <p>I need to find node by id in the tree. For that i am going down with help of two nested loops. But returned undefined.</p>
  
  <pre><code>function searchInTreeById(node, matchingId) {
      var res;
      if (node.select('id').get() == matchingId) {
          res = node.get();
          return res
      } else {
          if (node.exists('childObjects')) {
              node.select('childObjects').map(function (cursor, i) {
                  cursor.select('children').map(function (cursorChild, j) {
  
                      if (cursorChild.select('id').get() === matchingId) {
                          // console.log(cursorChild.get()) //this console.log is execute
                          res = cursorChild.get();
                          return res;
                      } else {
                          // console.log(cursorChild.get())
                          searchInTreeById(cursorChild, matchingId)
                      }
                  })
              })
          } else {
              res = node;
          }
      }
      return res
  }
  </code></pre>