title: JavaScript merging objects by id
body: <p>What's the correct way to merge two arrays in Javascript?</p>
  
  <p>I've got two arrays (for example):</p>
  
  <pre><code>var a1 = [{ id : 1, name : "test"}, { id : 2, name : "test2"}]
  var a2 = [{ id : 1, count : "1"}, {id : 2, count : "2"}]
  </code></pre>
  
  <p>I want to be able to end up with something like:</p>
  
  <pre><code>var a3 = [{ id : 1, name : "test", count : "1"}, 
            { id : 2, name : "test2", count : "2"}]
  </code></pre>
  
  <p>Where the two arrays are being joined based on the 'id' field and extra data is simply being added. </p>
  
  <p>I tried to use <code>_.union</code> to do this, but it simply overwrites the values from the second array into the first one</p>