title: Typescript/Javascript for loop on array, push value of a key to new array as key with the value 1 - if already exists, increment
body: <p>The purpose is to have an array with all of the unique values for a specific key from another array. Those unique values (now keys in the new array) will have as value the number of times they appear in the original array. </p>
  
  <p>This is my code so far:</p>
  
  <pre><code>for (let i = 0; i &lt; data.length; i++) {
  
  
             let theStupidKey = data[i].DeliveryStatus;
  
             if (
               this.differentValuesOfStatus.indexOf(theStupidKey) == "-1"
             ) {
               this.differentValuesOfStatus.push(theStupidKey: 1);
               // this.differentValuesOfStatus[theStupidKey].push(theStupidKey = 1);
             }
             else {
               this.differentValuesOfStatus[theStupidKey] = 1
             }
          }
          console.log(this.differentValuesOfStatus);
        };
  </code></pre>
  
  <p>But the syntax is wrong and I tried everything I could think of to make it work.</p>
  
  <p>Basically I'm looping through an array.</p>
  
  <p>If the value of the 'deliverystatus' key does not exist in the second array, I'm adding it with the value of "1".</p>
  
  <p>If it already exists, I want to add another number to it.</p>