title: Merge 2 objects based on 1 field using Underscore.js
body: <p>I have 2 arrays of objects:</p>
  
  <pre><code>var a = [
      { "image_id": 631293, "score": 73 }, 
      { "image_id": 11848407, "score": 56 }
  ];
  
  var b = [
      { "image_id": 631293, "article_id": 173 }, 
      { "image_id": 11848407, "article_id": 121 }
  ];
  </code></pre>
  
  <p>I have tried to apply method described in <a href="https://stackoverflow.com/a/27556833/3912805"><em>How can i merge array of objects with underscore js</em></a> but unfortunately it does not work at all.</p>
  
  <p>My need is to merge both arrays of objects thanks to <code>image_id</code>.</p>
  
  <p>So I tried this :</p>
  
  <pre><code>_.values(
     _.extendOwn(
        _.indexBy(a, 'image_id'),
        _.indexBy(b, 'image_id')
     )
  )
  </code></pre>
  
  <p>but output just return me this array of object a</p>
  
  <p>I need to get :</p>
  
  <pre><code>[
      {"image_id": 631293, "score": 73, "article_id": 173}, 
      {"image_id": 11848407, "score": 56, "article_id": 121}
  ]
  </code></pre>
  
  <p>How can I achieve this without doing a loop to check every element of array and use a <code>findWhere</code>?</p>