title: Merging inner objects by ID
body: <p>Hi I am trying to solve a problem. Initially I am getting data from an API like so</p>
  <pre><code>{
     &quot;questions&quot;:[
        {
           &quot;id&quot;:1,
           &quot;questionHeader&quot;:&quot;Some question header&quot;,
           &quot;questionText&quot;:&quot;Some question text?&quot;,
        },
        {
           &quot;id&quot;:2,
           &quot;questionHeader&quot;:&quot;Some question header&quot;,
           &quot;questionText&quot;:&quot;Some question text?&quot;,
        },
     ],
     &quot;answers&quot;:[
        {
           &quot;id&quot;:1,
           &quot;questionId&quot;:1,
           &quot;answer&quot;:&quot;Some answer&quot;,
        },
        {
           &quot;id&quot;:2,
           &quot;questionId&quot;:1,
           &quot;answer&quot;:&quot;Some answer&quot;,
        },
        {
           &quot;id&quot;:3,
           &quot;questionId&quot;:2,
           &quot;answer&quot;:&quot;Some answer&quot;,
        },
     ],
      &quot;answerText&quot;:[
        {
           &quot;id&quot;:1,
           &quot;answerId&quot;:1,
           &quot;text&quot;:&quot;Some text&quot;,
        },
        {
           &quot;id&quot;:2,
           &quot;answerId&quot;:2,
           &quot;text&quot;:&quot;Some text&quot;,
        },
        {
           &quot;id&quot;:3,
           &quot;answerId&quot;:3,
           &quot;text&quot;:&quot;Some text&quot;,
        },
     ]
  }
  </code></pre>
  <p>What I was initially after was to get the answers embedded within their respective question based on a questions id and an answers questionId. So for the above, I am trying to achieve something like the following.</p>
  <pre><code>{
     &quot;questions&quot;:[
        {
           &quot;id&quot;:1,
           &quot;questionHeader&quot;:&quot;Some question header&quot;,
           &quot;questionText&quot;:&quot;Some question text?&quot;,
           &quot;answers&quot;:[
            {
               &quot;id&quot;:1,
               &quot;questionId&quot;:1,
               &quot;answer&quot;:&quot;Some answer&quot;,
            },
            {
               &quot;id&quot;:2,
               &quot;questionId&quot;:1,
               &quot;answer&quot;:&quot;Some answer&quot;,
            },
          ]
        },
        {
           &quot;id&quot;:2,
           &quot;questionHeader&quot;:&quot;Some question header&quot;,
           &quot;questionText&quot;:&quot;Some question text?&quot;,
           &quot;answers&quot;:[
            {
              &quot;id&quot;:3,
              &quot;questionId&quot;:2,
              &quot;answer&quot;:&quot;Some answer&quot;,
            },
          ]
        },
     ],
  }
  </code></pre>
  <p>This was achieved by doing</p>
  <pre><code>const newItem = data.questions.map((t1) =&gt; ({
      ...t1,
      answers: data.answers.filter((t2) =&gt; t2.questionId === t1.id),
  }));
  </code></pre>
  <p>However, I now need to get the answerText embedded within the answers based on the id.  So the overall format should be</p>
  <pre><code>{
     &quot;questions&quot;:[
        {
           &quot;id&quot;:1,
           &quot;questionHeader&quot;:&quot;Some question header&quot;,
           &quot;questionText&quot;:&quot;Some question text?&quot;,
           &quot;answers&quot;:[
            {
               &quot;id&quot;:1,
               &quot;questionId&quot;:1,
               &quot;answer&quot;:&quot;Some answer&quot;,
               &quot;answerText&quot;:[
                  {
                     &quot;id&quot;:1,
                     &quot;answerId&quot;:1,
                     &quot;text&quot;:&quot;Some text&quot;,
                  },
               ]
            },
            {
               &quot;id&quot;:2,
               &quot;questionId&quot;:1,
               &quot;answer&quot;:&quot;Some answer&quot;,
               &quot;answerText&quot;:[
                  {
                     &quot;id&quot;:2,
                     &quot;answerId&quot;:2,
                     &quot;text&quot;:&quot;Some text&quot;,
                  },
               ]
            },
          ]
        },
        {
           &quot;id&quot;:2,
           &quot;questionHeader&quot;:&quot;Some question header&quot;,
           &quot;questionText&quot;:&quot;Some question text?&quot;,
           &quot;answers&quot;:[
            {
              &quot;id&quot;:3,
              &quot;questionId&quot;:2,
              &quot;answer&quot;:&quot;Some answer&quot;,
              &quot;answerText&quot;:[
                  {
                     &quot;id&quot;:3,
                     &quot;answerId&quot;:3,
                     &quot;text&quot;:&quot;Some text&quot;,
                  },
               ]
            },
          ]
        },
     ],
  }
  </code></pre>
  <p>How can this be achieved?  Thanks</p>