title: How to compare two arrays of objects in JavaScript using a key in object
body: <p>How to compare two arrays of objects in JavaScript using a key in object.I have two result sets like this. Is it possible to do something like this in JavaScript? or Lodash?</p>
  <pre><code>    // Array 1
          [
              { Id: &quot;0&quot;, display: &quot;Jamsheer 1&quot; },
              { Id: &quot;3&quot;, display: &quot;Muhammed 1&quot; },
          ]
      
      // Array 2
          [
              { Id: &quot;0&quot;, display: &quot;Jamsheer&quot; },
              { Id: &quot;1&quot;, display: &quot;Muhammed&quot; },
              { Id: &quot;2&quot;, display: &quot;Ravi&quot; },
              { Id: &quot;3&quot;, display: &quot;Ajmal&quot; },
              { Id: &quot;4&quot;, display: &quot;Ryan&quot; }
          ]
      
      
      The final result I need is - same id in array 2 should be replaced with corresponding id in array 1 – the final result should be like this:
      
      [
              { Id: &quot;0&quot;, display: &quot;Jamsheer 1&quot; },
              { Id: &quot;1&quot;, display: &quot;Muhammed&quot; },
              { Id: &quot;2&quot;, display: &quot;Ravi&quot; },
              { Id: &quot;3&quot;, display: &quot;Ajmal 1&quot; },
              { Id: &quot;4&quot;, display: &quot;Ryan&quot; }
          ]
  </code></pre>