I have below type of JSON response coming from backend. I am displaying this response in grid table. For that I need only array of "projects" objects throughout the whole response. I am not able to get all projects together.
[{
"responseText": "Success",
"userName": "[email protected]",
"userId": 2,
"projectDetails": [{
"accountName": "ViewEnvironment",
"projects": [{
"responseText": "success",
"id": 34,
"projectName": "Plato",
"accountName": "ViewEnvironment",
"projectHealth": null,
"modulesCount": 0,
"cordinatorEmail": null,
"businessType": null,
"projectType": null,
"status": null,
"createdDate": null,
"createdBy": null,
"modifiedDate": null,
"modifiedBy": null,
"role": "DL/PM",
"roleId": 3,
"projectUserId": 89
}]
},
{
"accountName": "Accloud",
"projects": [{
"responseText": "success",
"id": 4,
"projectName": "Citi Test2",
"accountName": "Accloud",
"projectHealth": null,
"modulesCount": 0,
"cordinatorEmail": null,
"businessType": null,
"projectType": null,
"status": null,
"createdDate": null,
"createdBy": null,
"modifiedDate": null,
"modifiedBy": null,
"role": "Executive",
"roleId": 2,
"projectUserId": 83
},
{
"responseText": null,
"id": 5,
"projectName": "Citi Test3",
"accountName": "Accloud",
"projectHealth": null,
"modulesCount": 0,
"cordinatorEmail": null,
"businessType": null,
"projectType": null,
"status": null,
"createdDate": null,
"createdBy": null,
"modifiedDate": null,
"modifiedBy": null,
"role": "Executive",
"roleId": 2,
"projectUserId": 221
},
{
"responseText": null,
"id": 9,
"projectName": "Test_Project",
"accountName": "Accloud",
"projectHealth": null,
"modulesCount": 0,
"cordinatorEmail": null,
"businessType": null,
"projectType": null,
"status": null,
"createdDate": null,
"createdBy": null,
"modifiedDate": null,
"modifiedBy": null,
"role": "Executive",
"roleId": 2,
"projectUserId": 220
}
]
},
{
"accountName": "iBASE",
"projects": [{
"responseText": "success",
"id": 1,
"projectName": "iBase-Project-edit",
"accountName": "iBASE",
"projectHealth": null,
"modulesCount": 0,
"cordinatorEmail": null,
"businessType": null,
"projectType": null,
"status": null,
"createdDate": null,
"createdBy": null,
"modifiedDate": null,
"modifiedBy": null,
"role": "Admin",
"roleId": 1,
"projectUserId": 70
},
{
"responseText": null,
"id": 1,
"projectName": "iBase-Project-edit",
"accountName": "iBASE",
"projectHealth": null,
"modulesCount": 0,
"cordinatorEmail": null,
"businessType": null,
"projectType": null,
"status": null,
"createdDate": null,
"createdBy": null,
"modifiedDate": null,
"modifiedBy": null,
"role": "Admin",
"roleId": 1,
"projectUserId": 72
},
{
"responseText": null,
"id": 1,
"projectName": "iBase-Project-edit",
"accountName": "iBASE",
"projectHealth": null,
"modulesCount": 0,
"cordinatorEmail": null,
"businessType": null,
"projectType": null,
"status": null,
"createdDate": null,
"createdBy": null,
"modifiedDate": null,
"modifiedBy": null,
"role": "Admin",
"roleId": 1,
"projectUserId": 73
},
{
"responseText": null,
"id": 1,
"projectName": "iBase-Project-edit",
"accountName": "iBASE",
"projectHealth": null,
"modulesCount": 0,
"cordinatorEmail": null,
"businessType": null,
"projectType": null,
"status": null,
"createdDate": null,
"createdBy": null,
"modifiedDate": null,
"modifiedBy": null,
"role": "Developer",
"roleId": 5,
"projectUserId": 74
}
]
}
]
}]
I tried to do this with nested for loop but with that only last array is coming not all arrays . Like below.
for (let user of this.selectedUser) {
this.projectList = user.projectDetails;
for (project of this.projectList) {
(this.projectList2) = project.projects;
for (let proj of this.projectList2) {
this.finalProjectsList = proj;
}
}
}
console.log("projcetlist", this.projectList.projects)
Can anybody suggest better approach to get right response.