Basic Recursion function

var createAncestorTree = function(current, level) {
  var levelString = "";
  if(!level) {
    level = 1;
  }
  for(var i = 0; i < level; i++) {
    levelString += "\t";
  }
  if(current.name) {
      treeString += current.name;
      for(var j = 0; j < current.children.length; j++){
        treeString += "\n" + levelString;
        createAncestorTree(current.children[j], level + 1);
      }
  }
};

Add your comment