title: Constructing alphabetized array of objects
body: <p>I have an array of objects with a name property... </p>
  
  <pre><code>var myList = [{
    name: 'Apple'
  }, {
    name: 'Nervousness',
  }, {
    name: 'Dry'
  }, {
    name: 'Assign'
  }, {
    name: 'Date'
  }]
  </code></pre>
  
  <p>Essentially, I am trying to create an array set up like this:</p>
  
  <pre><code>[{
    name: 'A',
    items: [{
      name: 'Apple'
    }, {
      name: 'Assign'
    }]
  }, {
    name: 'D',
    items: [{
      name: 'Date',
    }, {
      name: 'Dry',
    }]
  }, {
    name: 'N',
    items: [{
      name: 'Nervousness',
    }]
  }];
  </code></pre>
  
  <p>Basically, my array of objects needs to be alphabetized, placed into a new object with a parent key/value of 'name' with the corresponding letter.</p>
  
  <p>I can alphabetize them as follows...</p>
  
  <pre><code>myList.sort(function (a, b) {
    if (a.name &lt; b.name) return -1;
    if (a.name &gt; b.name) return 1;
    return 0;
  });
  </code></pre>
  
  <p>Then I can create an array of the first letters...</p>
  
  <pre><code>var headerLetters = [];
  angular.forEach(myList, function (item) {
    var firstLetter = item.name.charAt(0);
    if (headerLetters.indexOf(firstLetter) === -1) {
      headerLetters.push(firstLetter);
    }
  });
  </code></pre>
  
  <p>But then this is where I am stuck... I can check for duplicate first letters, but then how would I iterate through my list of objects and push them into a new object array in alphabetical order?</p>