1๐
โ
Iโm assuming that you have response data as array of object for both and need to add key not_eligible
in first response data based on id of first response data so i have update code it should work for you.
api.get(`get-participant-reports/${this.userData.ind_id}`)
.then((res) => {
this.reportData = res.data;
for (var i = 0; i < this.reportData.length; i++) {
api.get(`get-not-eligible360/${this.reportData[i].id}`).then((res) => {
this.reportData.forEach(reportItem => {
const existData = res.data.find(resItem => resItem.id === reportItem.id);
if (existData) {
reportItem.not_eligible = existData.not_eligible
}
});
console.log(this.reportData)
});
}
});
1๐
Try with findIndex and if found set object property:
api.get(`get-participant-reports/${this.userData.ind_id}`)
.then((res) => {
this.reportData = res.data;
for (var i = 0; i < this.reportData.length; i++) {
api.get(`get-not-eligible360/${this.reportData[i].id}`).then((res) => {
let idx = this.reportData.findIndex(i => i.id == res['0'].id)
if(idx > -1) this.reportData[idx].not_eligible = res['0'].not_eligible
});
}
});
Source:stackexchange.com