Create a Tree Node from JavaScript Array
Your code seems to only support 2 levels down. Also, the second loop is costly because it has to search through the array if the path already exists.

I believe your structure can be better represented using an object. Lookups won't need searching through, and there's still room for path metadata.

var goal = {
  // Room for "goal" metadata.
  "/": {},
  "A": {
    // Room for "A" metadata.
    subpaths: {
      "A": {},
      "B": {},
      "C": {},
    }
  },
  "B": {},
  "C": {},
}


Here's an example



var paths = [
  {path: "/"  },
  {path: "A"  },
  {path: "A.A"},
  {path: "A.B"},
  {path: "A.C"},
  {path: "A.D.C"},
  {path: "B"  },
  {path: "C"  }
];

// Move out or template into a creator function.
function createPath(){
  return {
    subpaths: {}
  };
}

// Resolves the path into objects iteratively (but looks eerily like recursion).
function resolvePath(root, path){
  path.split('.').reduce(function(pathObject, pathName){
    // For each path name we come across, use the existing or create a subpath
    pathObject.subpaths[pathName] = pathObject.subpaths[pathName] || createPath();
    // Then return that subpath for the next operation
    return pathObject.subpaths[pathName];
  // Use the passed in base object to attach our resolutions
  }, root);
}

var goal = paths.reduce(function(carry, pathEntry){
  // On every path entry, resolve using the base object
  resolvePath(carry, pathEntry.path);
  // Return the base object for suceeding paths, or for our final value
  return carry;
// Create our base object
}, createPath());

document.write(JSON.stringify(goal));