title: Wrap Properties of one Object to another - JavaScript
body: <p>May I know if using <code>reduce</code> I can achieve the following where the properties of <code>activatedItems</code> and <code>quarterItems</code> are wrapped in one object i.e., <code>modules</code>.</p>
  <pre><code>{
    &quot;isExternalVisitor&quot;: false,
    &quot;modules&quot;: [
      {
        &quot;moduleId&quot;: &quot;e569da0e-44e6-4f75-96c4-bdd888678abd&quot;,
        &quot;code&quot;: &quot;NEWQ2/SITENAME/2021-Q3-1&quot;,
        &quot;siteId&quot;: &quot;10babdbe-5346-43e8-932a-4c7ae54dcb1b&quot;,
        &quot;activatedId&quot;: &quot;2e03c658-3bbd-4332-bb1b-14fe56c7e753&quot;
      },
      {
        &quot;moduleId&quot;: &quot;588905b4-2c1d-49bf-a71f-84210405bc94&quot;,
        &quot;code&quot;: &quot;NEWQ1/SITENAME/2021-Q1-2&quot;,
        &quot;siteId&quot;: &quot;10babdbe-5346-43e8-932a-4c7ae54dcb1b&quot;,
        &quot;activatedId&quot;: &quot;6c1691d2-7c37-4888-a446-9219fa9b9014&quot;
      }
    ],
    &quot;activatedItems&quot;: [
      {
        &quot;activatedId&quot;: &quot;2e03c658-3bbd-4332-bb1b-14fe56c7e753&quot;,
        &quot;stQuarterId&quot;: &quot;b36d7e23-15e5-4f97-b52e-65757de4b264&quot;
      },
      {
        &quot;activatedId&quot;: &quot;6c1691d2-7c37-4888-a446-9219fa9b9014&quot;,
        &quot;stQuarterId&quot;: &quot;01000f98-6470-440a-a833-95b199ab1f7a&quot;
      }
    ],
    &quot;quarterItems&quot;: [
      {
        &quot;id&quot;: &quot;b36d7e23-15e5-4f97-b52e-65757de4b264&quot;,
        &quot;checklistId&quot;: &quot;8b479656-8cde-4bff-9c51-d5eca369bc76&quot;,
        &quot;fullName&quot;: &quot;dsad&quot;,
        &quot;year&quot;: &quot;2021-01-01T00:00:00&quot;,
        &quot;quarter&quot;: &quot;2021-Q3&quot;,
        &quot;versions&quot;: 1
      },
      {
        &quot;id&quot;: &quot;01000f98-6470-440a-a833-95b199ab1f7a&quot;,
        &quot;checklistId&quot;: &quot;039f2584-1ca5-4ee3-b46f-cdf1887af7f6&quot;,
        &quot;fullName&quot;: &quot;NEWQ1&quot;,
        &quot;year&quot;: &quot;2021-01-01T00:00:00&quot;,
        &quot;quarter&quot;: &quot;2021-Q1&quot;,
        &quot;versions&quot;: 2
      }
    ]
  }
  </code></pre>
  <p>This is the expected result where only one object has got all the data.</p>
  <pre><code>{
    &quot;isExternalVisitor&quot;: false,
    &quot;modules&quot;: [
      {
        &quot;moduleId&quot;: &quot;e569da0e-44e6-4f75-96c4-bdd888678abd&quot;,
        &quot;code&quot;: &quot;NEWQ2/SITENAME/2021-Q3-1&quot;,
        &quot;siteId&quot;: &quot;10babdbe-5346-43e8-932a-4c7ae54dcb1b&quot;,
        &quot;activatedId&quot;: &quot;2e03c658-3bbd-4332-bb1b-14fe56c7e753&quot;,
        &quot;stQuarterId&quot;: &quot;b36d7e23-15e5-4f97-b52e-65757de4b264&quot;,
        &quot;checklistId&quot;: &quot;8b479656-8cde-4bff-9c51-d5eca369bc76&quot;,
        &quot;fullName&quot;: &quot;dsad&quot;,
        &quot;year&quot;: &quot;2021-01-01T00:00:00&quot;,
        &quot;quarter&quot;: &quot;2021-Q3&quot;,
        &quot;versions&quot;: 1
      },
      {
        &quot;moduleId&quot;: &quot;588905b4-2c1d-49bf-a71f-84210405bc94&quot;,
        &quot;code&quot;: &quot;NEWQ1/SITENAME/2021-Q1-2&quot;,
        &quot;siteId&quot;: &quot;10babdbe-5346-43e8-932a-4c7ae54dcb1b&quot;,
        &quot;activatedId&quot;: &quot;6c1691d2-7c37-4888-a446-9219fa9b9014&quot;,
        &quot;stQuarterId&quot;: &quot;01000f98-6470-440a-a833-95b199ab1f7a&quot;,
        &quot;checklistId&quot;: &quot;039f2584-1ca5-4ee3-b46f-cdf1887af7f6&quot;,
        &quot;fullName&quot;: &quot;NEWQ1&quot;,
        &quot;year&quot;: &quot;2021-01-01T00:00:00&quot;,
        &quot;quarter&quot;: &quot;2021-Q1&quot;,
        &quot;versions&quot;: 2
      }
    ]
  }
  </code></pre>
  <p>I tried the following and was able to merge them in one array, but however, the end result is not the same as above. Your kind help will be appreciated.</p>
  <pre><code>let modules = arr.modules;
  let activatedItems = arr.activatedItems;
  let quarterItems = arr.quarterItems;
  let finalArr = [];
  
  modules.forEach(module =&gt; {
      activatedItems.forEach(item =&gt;{
          if(item.activatedId == module.activatedId)
          {
             quarterItems.forEach(quaItem =&gt; {
                if(quaItem.id == item.stQuarterId){
                   finalArr.push(module);
                   finalArr.push(item);
                   finalArr.push(quaItem);
                }
             }) 
          }
      })
  })
  </code></pre>