title: group array by groups and sort by position
body: <p>I have an array.  I need to group this array by groups and sort by position.  I tied to create a new array with group names as keys and values as sorted array grouped by group, but didn't work well.  How can I do this?</p>
  
  <pre><code>a = [
      {id:1,name:'qw'group:'C',name:'hite',position:'1'},
      {id:2,name:'qwe'group:'B',name:'ite',position:'2'},
      {id:3,name:'qwer'group:'A',name:'ite',position:'3'},
      {id:4,name:'qer'group:'D',name:'te',position:'4'},
      {id:5,name:'wer'group:'C',name:'whit',position:'5'},
      {id:6,name:'er'group:'B',name:'whi',position:'6'},
  ]
  
  function groupDo(array){                
    var groups = [];
    for (var i in array){
      groups[array[i].group] = array[i].group;
    }
    for (var i in array){
      if (groups[array[i].group] == array[i].group){
        groups[array[i].group] = array[i];
      }
     }
  }
  </code></pre>