title: How to combine multiple JSON objects where key value is the same
body: <p>I'm trying to combine objects which share the same module key value, i.e. "credit cards". I need to return a single object per unique module with an array of distinct companies. The id and prod keys aren't important.</p>
  
  <p><strong>Here's the object I need to transform:</strong></p>
  
  <pre><code>const data = [
     {module: "credit_cards", id: "1", company: "ABC", prod: "1"}, 
     {module: "credit_cards", id: "2", company: "XYZ", prod: "2"}, 
     {module: "credit_cards", id: "3", company: "EFG", prod: "2"}, 
     {module: "credit_cards", id: "2", company: "XYZ", prod: "2"}, 
     {module: "mortgages", id: "4", company: "EFG", prod: "3"}
  ]
  </code></pre>
  
  <p><strong>I need to return something like this:</strong></p>
  
  <pre><code>const result = [
  {module: "credit_cards", company: ["ABC", "XYZ", "EFG"]}, 
  {module: "mortgages", company: ["EFG"]}
  ]
  </code></pre>
  
  <p>So far, I've tried this function:</p>
  
  <pre><code>const result = data.reduce(function(r, e) {
    return Object.keys(e).forEach(function(k) {
      if(!r[k]) r[k] = [].concat(e[k])
      else r[k] = r[k].concat(e[k])
    }), r
  }, {})
  </code></pre>
  
  <p>But it just concatenated all the key/values together...</p>
  
  <p>Any help would be awesome, thanks :)</p>