title: Javascript Recursion returning undefined
body: <p>I'm struggling in a recursive Javascript function to find a specific subdirectory. This is my code:</p>
  
  <pre><code>function navigateToParent() {
      var parentFullPath = parentDirectory(); // gets the full Path String
      if (parentFullPath != null) {
          var parent = getDirectoryByName(parentFullPath, rootDirectory);
          // set the parent directory object as the current one
          currentDirectory(parent);
      }
  }
  
  function getDirectoryByName(fullName, myDirectory) {
      if (myDirectory.fullName == fullName) {
          return myDirectory;
      } else {
          var subs = myDirectory.subDirectories;
          for (i = 0; i &lt; subs.length; i++) {
              return getDirectoryByName(fullName,subs[i]);
          }
      }
  }
  </code></pre>
  
  <p>Every directory object has the properties <code>fullName</code>(string),<code>subDirectories</code>(array of directories) and <code>files</code>(array of files). My aim is to get the correct directory object, where it's fullName is matching.</p>
  
  <p>I know, that i have to break the for loop in some way, but i don't know how to do it exactly.</p>