title: Merge array of objects in efficient way
body: <p>I have below scenario where I am trying to merge two array of objects.</p>
  
  <p>The current code works, but I am looking for a more efficient way.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var constList = [
    { name: "jack", id: "1", designation: "hr" },
    { name: "mary", id: "2", designation: "it" },
    { name: "john", id: "3", designation: "fin" }
  ]
  
  var apiList = [
    { name: "jack", id: "1", height: "10" },
    { name: "mary", id: "2", height: "20" }
  ]
  
  var temp = [];
  
  constList.forEach(x =&gt; {
    apiList.forEach(y =&gt; {
      if (x.id === y.id) {
        temp.push({ ...x,
          ...y
        });
      }
    });
  });
  
  console.log(temp);</code></pre>
  </div>
  </div>
  </p>
  
  <p>Only the matching elements from apiList should be merged with constList.</p>
  
  <p>The output is correct, can anyone guide me with best way to to it.</p>