Here is the format which my code is generating:
[
    {
        "certifications": [
            {
                "certificate": "NA",
                "completed_on": "2019-09-24T18:30:00.000Z",
                "tc_name": "TC-174195"
            }
        ],
        "firstname": "Dipak",
        "lastname": "Das",
        "email": "dasdipak99@gmail.com"
    }
]
And I wanted to design like below format:
[
  {
    firstname: "Dipak",
    lastname: "Das",
    email: "dasdipak99@gmail.com",
    certifications: [
      {
        certificate: "NA",
        completed_on: "2019-09-24T18:30:00.000Z",
        tc_name: "TC-174195"
      }
    ]
  }
]
Below is my code :
var user = [];
var certificate = {
  certifications: []
};
certificate["firstname"] = rows[0].firstname;
certificate["lastname"] = rows[0].lastname;
certificate["email"] = rows[0].email;
for (let i = 0; i < rows.length; ++i) {
  certificate.certifications.push({
    certificate: rows[i].certification_names,
    completed_on: rows[i].completed_on,
    tc_name: rows[i].tc_name
  });
}
Any ideas how to maintain the insertion order? I am very new to javascript, apologies if i haven't explain well.
 
     
    