title: recursive function returns undefined on second run
body: <p>I have a recursive function that runs over my object (nested object with children) and it returns an object back as a result (which works as it should), but when the function is called within another function, the second time the function runs it returns undefined.</p>
  
  <p>this is the initiator:</p>
  
  <pre><code>$('a').click(function(){
      if($(this).hasClass('open')){
          return null;
      }
      console.log(this);
      var parentId = $(this).attr('id');
      var children = searchForChildrenByParentId(currentParentObject, parentId);
      console.log(children);
      if(children){
          var ul = $(this).children();
          children.forEach(function(child){
              var li = addLi(child);
              applyLiToUl(ul, li);
              init();
          })
      }
      $(this).addClass('open');
  })
  </code></pre>
  
  <p>and the recursive function:</p>
  
  <pre><code>function searchForChildrenByParentId(obj, stack){
      for (var property in obj) {
          if (property == "id") {
              if(obj.id == stack ){
                  console.log(obj.children);
                  return obj.children;
              } else if (obj.hasOwnProperty("children")){
                  obj.children.forEach(function(child){
                      searchForChildrenByParentId(child, stack);
                  })
              } else {
                  return null;
              }
          }
      }
  }
  </code></pre>
  
  <p>The recursive function does its job as it should, works great, the initiator also works (on the first run).</p>
  
  <p>The first console.log in the initiator returns the correct element,
  the console log (in the recursive function) logs the correct object, but when the object is returned to the initiator the console log there gives me undefined?</p>