title: How to form an array of nested arrays in my specific case?
body: <p>I have a specific usecase where I want to combine all objects from an array into one new array. So I have a form in my website where users while booking are adding participants. They can add as many participants as they want. I save them in database as JSON and now I want to form a array of all participants so that I can show them all in the table.</p>
  <p>So I first fetch all transactions from a specific listing which I get as an Array of objects and then I loop through them all and only get the <code>transaction.attributes.protectedData.questions</code> which holds the participants of each transaction.</p>
  <p>So my transactions object looks like:</p>
  <pre><code>[
     {
        &quot;type&quot;:&quot;transaction&quot;,
        &quot;attributes&quot;:{
           &quot;createdAt&quot;:&quot;2021-06-24T08:50:26.911Z&quot;,
           &quot;protectedData&quot;:{
              &quot;questions&quot;:[
                 [
                    {
                       &quot;question&quot;:&quot;name&quot;,
                       &quot;answer&quot;:&quot;Mario North&quot;
                    },
                    {
                       &quot;question&quot;:&quot;email&quot;,
                       &quot;answer&quot;:&quot;mario@gmail.com&quot;
                    }
                 ]
              ],
              &quot;ticketType&quot;:{
                 &quot;name&quot;:&quot;Main entry&quot;,
                 &quot;quantity&quot;:1
              }
           }
        }
     },
     {
        &quot;type&quot;:&quot;transaction&quot;,
        &quot;attributes&quot;:{
           &quot;createdAt&quot;:&quot;2021-06-24T08:48:57.646Z&quot;,
           &quot;protectedData&quot;:{
              &quot;questions&quot;:[
                 [
                    {
                       &quot;question&quot;:&quot;name&quot;,
                       &quot;answer&quot;:&quot;John Adkins&quot;
                    },
                    {
                       &quot;question&quot;:&quot;email&quot;,
                       &quot;answer&quot;:&quot;john@gmail.com&quot;
                    }
                 ],
                 [
                    {
                       &quot;question&quot;:&quot;name&quot;,
                       &quot;answer&quot;:&quot;Thomas Smith&quot;
                    },
                    {
                       &quot;question&quot;:&quot;email&quot;,
                       &quot;answer&quot;:&quot;thomas@gmail.com&quot;
                    }
                 ]
              ],
              &quot;ticketType&quot;:{
                 &quot;name&quot;:&quot;General entry&quot;,
                 &quot;quantity&quot;:2
              }
           }
        }
     }
  ]
  </code></pre>
  <p>So I need to loop through each transaction, then loop through questions and each new array in questions array is a new participant. In each participant I need to save the createdAt and ticketType values from transaction property.</p>
  <p>So my final array/object needs to look like this:</p>
  <pre><code>[
     {
        &quot;createdAt&quot;:&quot;2021-06-24T08:50:26.911Z&quot;,
        &quot;ticketType&quot;:&quot;Main entry&quot;,
        &quot;name&quot;:&quot;Mario North&quot;,
        &quot;email&quot;:&quot;mario@gmail.com&quot;
     },
     {
        &quot;createdAt&quot;:&quot;2021-06-24T08:48:57.646Z&quot;,
        &quot;ticketType&quot;:&quot;General entry&quot;,
        &quot;name&quot;:&quot;John Adkins&quot;,
        &quot;email&quot;:&quot;john@gmail.com&quot;
     },
     {
        &quot;createdAt&quot;:&quot;2021-06-24T08:48:57.646Z&quot;,
        &quot;ticketType&quot;:&quot;General entry&quot;,
        &quot;name&quot;:&quot;Thomas Smith&quot;,
        &quot;email&quot;:&quot;thomas@gmail.com&quot;
     }
  ]
  </code></pre>
  <p>So I can get the list of participants with createdAt and ticketType added to each of them. But I don't know how can I get my question/answer to appear as my wanted object I posted upper. This is what I have:</p>
  <pre><code>export const denormalisedParticipantList = transactions =&gt; {
    let participants = [];
  
    transactions.map(transaction =&gt; {
      const createdAt = transaction.attributes.createdAt;
      const questions = transaction.attributes.protectedData?.questions;
      const ticketType = transaction.attributes.protectedData?.ticketType?.name;
  
      return questions.map(q =&gt; {
        // Form new participant object
        const participant = {
          createdAt,
          ticketType,
          ...Object.fromEntries(q.map(({ question, answer }) =&gt; [question, answer])),
        };
  
        // Push new participant
        participants.push(participant);
      });
    });
  
    return participants;
  };
  </code></pre>
  <p>I've been trying to figure it out since last night and I can't make it work. Can anyone please help me figure out how can I make a final array from my transactions object, I would be extremly thankful.</p>