Iterate the outer array, then — in each inner array iteration — push the data you want in your result:
const input = [
{
MC: "11233",
jobid: 113331,
list: [
{ Q1: 1113, Q2: 333, code: "thisis1" },
{ Q1: 333, Q2: 111, code: "thisis2" },
{ Q1: 333, code: "thisis3" },
],
},
{
MC: "332211",
jobid: 3333,
list: [
{ Q1: 444, Q2: 555, code: "thisis4" },
],
},
];
const result = [];
for (const {MC, jobid, list} of input) {
for (const {Q1, Q2, code} of list) {
result.push(({MC, jobid, Q1, Q2, code}));
}
}
console.log(result);
jsejcksn
- 34.6k
- 5
- 55
- 79