title: Nodejs how to create a `data tree` with array on result
body: <p>How to fix or redesign results or create a TreeView after mapping the result using nodejs?
  this is my code, please check below the desired result</p>
  <p>What I want here is that if the QuestionGroupID is existing it will not create another row but it will create array on <code>optionItems</code></p>
  <p>please see the desired result vs current result to understand what i mean</p>
  <pre><code>const getquestionnaire = await QuestionnaireModels.getQuestion(yearlevel, section);
  const desiredResult = currentResult.map(({ yearlevel, section, Groupname, _id, QuestionDescription, OptionDescription }) =&gt; ({
     yearlevel,
     section,
     question: {
        Groupname,
        groupdetails: {
           QuestionGroupID,
           QuestionDescription,
           optionItems: {
              OptionDescription
           }
        }
     }
  }))
  res.send(getquestionnaire);
  </code></pre>
  <p>getQuestion</p>
  <pre><code>async getQuestion(yearlevel, section) {
      let student = await Database.getConnection().models.student;
      let qgroup = await Database.getConnection().models.questiongroups;
      let qdetails = await Database.getConnection().models.questiondetails;
      let oitem = await Database.getConnection().models.optionitems;
      student.hasMany(qgroup, { foreignKey: '_id'});
      student.hasMany(qdetails, {foreignKey: 'QuestionGroupID'});
      let question = await Database.getConnection().models.student.findAll({
       attributes:[
      'yearlevel','section','questiondetails.QuestionGroupID','questiongroups.GroupName','questiondetails.QuestionDescription','optionitems.OptionDescription'
      ],
        where: {
          yearlevel: yearlevel,
          section: section
        },
        include:[
          { model: qgroup, attribute:[] },
          { model: qdetails, attribute:[] },
      ],
        raw: true,
      })
      return result
    },
    let org_data = question.map(async data =&gt; {
          let item = await oitem.findAll({
              attributes: ['OptionDescription'],
              where: {QuestionDetailsID: data.QuestionGroupID},
              raw: true
          })
          
          return  item
      })
  </code></pre>
  <p>current result</p>
  <pre><code>[
      {
          &quot;yearlevel&quot;: &quot;Grade 7&quot;,
          &quot;section&quot;: &quot;Apple&quot;,
          &quot;question&quot;:{
              &quot;Groupname&quot;: &quot;Third&quot;,
              &quot;groupdetail&quot;:{
                  &quot;QuestionGroupID&quot;: 1,
                  &quot;QuestionDescription&quot;:&quot;Eating Disorder&quot;,
                  &quot;optionItems&quot;:{
                      &quot;OptionDescription&quot;: &quot;Test 1&quot;
                  }
              }
          }
      },
      {
          &quot;yearlevel&quot;: &quot;Grade 7&quot;,
          &quot;section&quot;: &quot;Orange&quot;,
          &quot;question&quot;:{
              &quot;Groupname&quot;: &quot;Third&quot;,
              &quot;groupdetail&quot;:{
                  &quot;QuestionGroupID&quot;: 1,
                  &quot;QuestionDescription&quot;:&quot;Eating Disorder&quot;,
                  &quot;optionItems&quot;:{
                      &quot;OptionDescription&quot;: &quot;Test 2&quot;
                  }
              }
          }
      },
      {
          &quot;yearlevel&quot;: &quot;Grade 8&quot;,
          &quot;section&quot;: &quot;Blue&quot;,
          &quot;question&quot;:{
              &quot;Groupname&quot;: &quot;Test Group name&quot;,
              &quot;groupdetail&quot;:{
                  &quot;QuestionGroupID&quot;: 2,
                  &quot;QuestionDescription&quot;:&quot;Test Question&quot;,
                  &quot;optionItems&quot;:{
                      &quot;OptionDescription&quot;: &quot;Test&quot;
                  }
              }
          }
      }
  ]
  </code></pre>
  <p>desired result</p>
  <pre><code>[
      {
          &quot;yearlevel&quot;: &quot;Grade 7&quot;,
          &quot;section&quot;: &quot;Apple&quot;,
          &quot;question&quot;:{
              &quot;Groupname&quot;: &quot;Third&quot;,
              &quot;groupdetail&quot;:{
                  &quot;QuestionGroupID&quot;: 1,
                  &quot;QuestionDescription&quot;:&quot;Eating Disorder&quot;,
                  &quot;optionItems&quot;:[
                      {
                          &quot;OptionDescription&quot;: &quot;Test 1&quot;
                      },
                      {
                          &quot;OptionDescription&quot;: &quot;Test 2&quot;
                      }
                  ]
              }
          }
      },
  
      {
          &quot;yearlevel&quot;: &quot;Grade 8&quot;,
          &quot;section&quot;: &quot;Blue&quot;,
          &quot;question&quot;:{
              &quot;Groupname&quot;: &quot;Test Group name&quot;,
              &quot;groupdetail&quot;:{
                  &quot;QuestionGroupID&quot;: 2,
                  &quot;QuestionDescription&quot;:&quot;Test Question&quot;,
                  &quot;optionItems&quot;:{
                      &quot;OptionDescription&quot;: &quot;Test&quot;
                  }
              }
          }
      }
  ]
  </code></pre>
  <p>this is related on this <a href="https://stackoverflow.com/questions/73687555/nodejs-how-to-create-a-data-tree-on-result">Nodejs how to create a `data tree` on result</a> but different problem</p>
  <blockquote>
  <p>dont mind this message dont mind this message dont mind this message
  dont mind this message dont mind this message dont mind this message
  dont mind this message dont mind this message dont mind this message</p>
  </blockquote>