title: Sort and group objects alphabetically by first letter Javascript
body: <p>Im trying to create a collection like this in order to use in a react component:</p>
  
  <pre><code>let data = [
      { 
          group : 'A', 
          children : [
              { name : 'Animals', id : 22 },
              ...
          ]
      },
      { 
          group : 'B', children : [
              { name : 'Batteries', id : 7},
              { name : 'Baggage', id : 12 },
              ...
          ]
      },
      { 
          group : 'C', children : [
              { name : 'Cake', id : 7},
              ...
          ]
      },
  ]
  </code></pre>
  
  <p> I've already sort my data like this :</p>
  
  <pre><code>let rawData = [
      { name : 'Animals', id : 10},
      { name : 'Batteries', id : 7},
      { name : 'Baggage', id : 12 },
      { name : 'Cake', id : 7},
      ...
  ]
  </code></pre>
  
  <p>Also I used this <a href="https://stackoverflow.com/questions/43750568/sorting-json-alphabetically-by-first-letter">sorting method</a> but the problem is, it's returning an Object with <code>A</code>, <code>B</code>, <code>C</code> keys with children as values. But I have to turn it into array like above in order to use that.</p>
  
  <p>Here is what i've tried so far :</p>
  
  <pre><code>let data = rawData.reduce(function(prevVal, newVal){   
      char = newVal.name[0].toUpperCase();
      return { group: char, children :{name : newVal.name, id : newVal.id}};
  },[])
  </code></pre>