title: JavaScript Group By Array
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5217136/array-count-values-for-javascript-instead">array_count_values for javascript instead</a>  </p>
  </blockquote>
  
  
  
  <p>Let's say I have simple JavaScript array like the following:</p>
  
  <pre><code>var array = ['Car', 'Car', 'Truck', 'Boat', 'Truck'];
  </code></pre>
  
  <p>I want to group and count of each so I would expect a key/value map of:</p>
  
  <pre><code>{
    Car   : 2,
    Truck : 2,
    Boat  : 1
  }
  </code></pre>