i want to create a new array from api, but i don't know how to make it, i'm very confused in looping each array
This is each data
const group_one = [
{
name: "smash",
id: "012112"
},
{
name: "ahlan wa sahlan",
id: "123123"
},
{
name: "ahh",
id: "1231239"
},
{
name: "laki",
id: "21312"
}
];
const group_two = [
{
name: "ahh",
id: "1231239"
},
{
name: "laki",
id: "21312"
}
];
const group_three = [
{
name: "smash",
id: "012112"
},
{
name: "ahlan wa sahlan",
id: "123123"
}
];
this is the main data of api
const data = [
{
body: group_one,
group_id: "01"
},
{
body: grouop_two,
group_id: "02"
},
{
body: group_three,
group_id: "03"
}
];
export default data;
i want to create a new array like this, bcs i want to create a new object containing the group_id of each same data in the array
const newArray = [
{
name: "smash",
id: "012112",
group_id: ["01","03"]
},
{
name: "ahlan wa sahlan",
id: "123123",
group_id: ["01","03"]
},
{
name: "ahh",
id: "1231239",
group_id: ["01","02"]
},
{
name: "laki",
id: "21312",
group_id: ["01","02"]
}
];
can someone help me? with articles or codes. thanks for helping me (sry for my bad english)