title: Creating a nested Javascript object
body: <p>I apparently cannot think abstractly enough to do this... but I'd like to create a Javascript object out of an array that uses the array values as property names, but they should be nested objects within each other.</p>
  
  <p>So if I had an array like this:</p>
  
  <pre><code>['First', 'Second', 'Third', 'Fourth']
  </code></pre>
  
  <p>My expected output would be:</p>
  
  <pre><code>{
      First: {
          Second: {
              Third: {
                  Fourth: {}
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  Here is the function I was using as mentioned in the commment:</p>
  
  <pre><code>function appendKey(obj, to, key) {
      if (obj.hasOwnProperty(to)) {
          appendKey(obj[to], to, key);
      } else {
          obj[key] = {};
      }
  
      return obj;
  }
  </code></pre>
  
  <p>My intent was to call it as such:</p>
  
  <pre><code>var data = ['First', 'Second', 'Third', 'Fourth'];
  data = appendKey(data, 'First', 'Second');
  data = appendKey(data, 'Second', 'Third');
  data = appendKey(data, 'Third', 'Fourth');
  </code></pre>
  
  <p>Clearly that could be put into a loop, which is why I wanted to do it that way. My output ended up being:</p>
  
  <pre><code>data = { 'First' : { 'Second' } } // it works this time!
  
  data = { 'First' : { 'Second' },
           'Third' : { } }
  
  data = { 'First' : { 'Second' },
           'Third' : { 'Fourth' { } } } 
  </code></pre>