title: AngularJS - Group by array
body: <p>I have a scope array of locations, each location can be in one or more categories.<br>
  For eaxmple:</p>
  
  <pre><code>Locations: [{id: 1,
    name: "NJ",
    categories: [0, 2, 3]
  },{
    id: 2,
    name: "NY",
    categories: [0, 2]
  }]
  
  Categories: [{
    id: 0,
    name: "Cities"
  }, {
    id: 2,
    name: "Canyons"
  }, {
    id: 3,
    name: "Work"
  }]
  </code></pre>
  
  <p>In my app I display all of the locations with this code:</p>
  
  <pre><code>&lt;div ng-repeat="row in rows"&gt;
      {{ row.name }}&lt;br&gt;
      Categories: &lt;span enum-categories="row"&gt;&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Now I want to add the option to group the items by their categories..<br>
  My problem is that each item can have more than one category..</p>
  
  <p>The result need to be something like this:</p>
  
  <pre><code>cat 0:
  NJ, NY
  
  cat 1:
  Nothing
  
  cat 2:
  NJ, NY
  
  cat 3:
  NJ
  </code></pre>
  
  <p>How can I do this?<br>
  Thank you :)</p>