title: Javascript count duplicates and uniques and add to array
body: <p>I'm trying to count duplicates in an array of dates and add them to a new array.</p>
  
  <p>But i'm only getting the duplicates and the amount of times they exist in the array. </p>
  
  <p>What I want is:</p>
  
  <p><code>[a, a, b, c, c]</code> => <code>[a: 2, b: 1, c: 2]</code></p>
  
  <p>Code:</p>
  
  <pre><code>$scope.result = { };
      for(var i = 0; i &lt; $scope.loginArray.length; ++i) {
          if(! $scope.result[$scope.loginArray[i]]){
               $scope.result[$scope.loginArray[i]] = 0;
          ++ $scope.result[$scope.loginArray[i]];}
      }
  </code></pre>
  
  <p>Any suggestions?</p>