I am trying to populate my predefined data property.
reportGroupData: [
{
program_name: "",
iteration_name: "",
report_template_name: "",
toggle: true,
report_details: [],
},
]
this is my API, and the code I try to populate my predefined data property. I'm using async in this BTW.
api.get(`get-coach-reports/${this.userData.ind_id}`).then((res) => {
this.reportData = res.data;
this.reportGroupData.forEach(element => {
this.reportData.forEach((mapElement)=>{ //i tried using map in here but same result
element.program_name = mapElement.program_name
element.iteration_name = mapElement.iteration_name
element.report_template_name = mapElement.report_template_name
element.report_details.push(this.reportData)
})
});
This is the data we get from my API, res.data:
[
{
"full_name": "Arnd Philipp Von Frese Von Issendorff",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
},
{
"full_name": "Arnd Philipp Von Frese Von Issendorff 123",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
},
{
"full_name": "Arnd Philipp Von Frese Von Issendorff 321",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
},
{
"full_name": "Chris Hallett",
"report_file": "TeamLeader360Report.html",
"report_template_name": "Team Leader 360 Coach Report",
"suborg_name": "Sandbox",
"program_name": "LBS Test Programme",
"iteration_name": "TEST2022"
},
{
"full_name": "John Doe",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
},
{
"full_name": "John Doe 123",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
}
]
I'm trying to achieve this result:
[
{
"report_template_name": "Five STeP Profile Coach Report",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023",
"toggle": true,
"report_details":[
{
"full_name": "Arnd Philipp Von Frese Von Issendorff",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
},
{
"full_name": "Arnd Philipp Von Frese Von Issendorff 123",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
},
{
"full_name": "Arnd Philipp Von Frese Von Issendorff 321",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
}
]
},
{
"report_template_name": "Team Leader 360 Coach Report",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023",
"toggle": true,
"report_details":[
{
"full_name": "John Doe",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
},
{
"full_name": "John Doe 123",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
}
]
},
{
"report_template_name": "Pressure Point 'Big 5' Coach Report",
"program_name": "Senior Executive Programme (SEP)",
"iteration_name": "SEP107",
"toggle": true,
"report_details":
[
{
"full_name": "Chris Hallett",
"report_file": "TeamLeader360Report.html",
"report_template_name": "Pressure Point 'Big 5' Coach Report",
"suborg_name": "Sandbox",
"program_name": "Senior Executive Programme (SEP)",
"iteration_name": "SEP107"
}
]
}
]
This is what I get in my console, It just populates the report_details inside my reportGroupData

I also tried this solution in here Reconstructing array but the spread / rest operator returns an error inside my forEach or map. Is it because I'm using Vue not just vanilla javascript?