title: How to create a new array with a nested array as specific key value in JavaScript
body: <p>If have an array like this:</p>
  
  <pre><code>let array = [ 
               {hash: "11223344", value: "abc"},
               {hash: "11223344", value: "def"},
               {hash: "22113344", value: "jkl"},
               {hash: "22113344", value: "zyw"},
               {hash: "33221144", value: "omn"},
               {hash: "33221144", value: "xyz"}
  ];
  </code></pre>
  
  <p>and I wanted to loop through that array and create a new array whereby each each <code>hash</code> is only listed once and each <code>value</code> that was listed with a given is added to an array at the key value in the object of the single <code>hash</code>, like this:</p>
  
  <pre><code>let newarray = [ 
               {hash: "11223344", value: ["abc", "def"]},
               {hash: "22113344", value: ["jkl", "zyw"]},
               {hash: "33221144", value: ["omn", "xyz"]},
  ]; 
  </code></pre>
  
  <p>How would I get there?</p>
  
  <p>Im thinking its something like</p>
  
  <pre><code>array.map((item, i, self) =&gt; {
      let newArray =[];
      if(item.hash === newArray.hash){
          newArray.value.concat(item.value)
      } else {
          newArray.concat({hash: item.hash, value: [item.value]})
  }
  </code></pre>
  
  <p>but how do I instantiate that array at first in the <code>value</code> key?
  Is my thinking right on the use of the <code>Array.prototype.map()</code>?</p>
  
  <p><strong>EDIT</strong>: I was asked to explain how this question is different than: <a href="https://stackoverflow.com/questions/40774697/how-to-group-an-array-of-objects-by-key">How to group an array of objects by key</a></p>
  
  <p>In contrast to the link, there is no need to group the results and I dont want to use a library like LoDash. The clarity provided about creating the array in the <code>value</code> key also has some worth.  </p>
  
  <p>I think the answers here also point out the need to use the index and provides several valid tools, some of which arent provided in the answers in the other questions.  Tools such as <code>reduce()</code> and <code>Set</code></p>