I am seeking assistance with a JavaScript problem.
Despite researching and trying different solutions for hours, I am still missing something crucial.
It seems like a simple task, so please forgive my lack of knowledge.
How can I loop through an Array of Objects within Objects in JavaScript?
I have learned that one should use a for...in loop for arrays and a simple for loop for objects. However, I am struggling to figure out how to loop through an array of objects within an object.
Here is my goal:
I want to display a list of reports (report names) in my UI that match a specific ReportTemplateTypeId.
To achieve this, I need to iterate through my retrieved data after making a data call to build the list.
The report names I want to display must have a ReportTemplateTypeId equal to 1.
My retrieved data looks like this: SelectableReportTemplateNames: [{{}},{{}},{{}},{{}}] containing an Object within an Object within an Array.
Below is an example of the data, featuring 4 records I would like to add to my list:
"SelectableReportTemplateNames": [
{
"ReportTemplateId": 1,
"ReportTemplateName": "Proof of Receipt",
"ReportTemplatePath": "...rdlc",
"ReportTemplateType": {
"ReportTemplateTypeId": 2,
"ReportTemplateTypeDescription": "Inventory - Proof of Receipt",
"Id": null
},
"Id": "5653781274d4f23d4cbb54b8"
},
{
"ReportTemplateId": 2,
"ReportTemplateName": "Proof of Transfer",
"ReportTemplatePath": ".....rdlc",
"ReportTemplateType": {
"ReportTemplateTypeId": 3,
"ReportTemplateTypeDescription": "Inventory - Proof of Transfer",
"Id": null
},
"Id": "5653781274d4f23d4cbb54b9"
},
{
"ReportTemplateId": 11,
"ReportTemplateName": "All Calls Report",
"ReportTemplatePath": "....rdlc",
"ReportTemplateType": {
"ReportTemplateTypeId": 1,
"ReportTemplateTypeDescription": "All Calls Report",
"Id": null
},
"Id": "5739a89577801d7f0c10254c"
},
{
"ReportTemplateId": 12,
"ReportTemplateName": "High Priority Calls Report",
"ReportTemplatePath": "......rdlc",
"ReportTemplateType": {
"ReportTemplateTypeId": 1,
"ReportTemplateTypeDescription": "High Priority Calls Report",
"Id": null
},
"Id": "5739a89e77801d7f0c10254d"
},
{
"ReportTemplateId": 13,
"ReportTemplateName": "Call Asset Lines Report",
"ReportTemplatePath": "......rdlc",
"ReportTemplateType": {
"ReportTemplateTypeId": 1,
"ReportTemplateTypeDescription": "Call Asset Lines Report",
"Id": null
},
"Id": "5739aa7d77801d7f0c10254e"
},
{
"ReportTemplateId": 16,
"ReportTemplateName": "Daily Status Report",
"ReportTemplatePath": ".....rdlc",
"ReportTemplateType": {
"ReportTemplateTypeId": 1,
"ReportTemplateTypeDescription": "Daily Status Report",
"Id": null
},
"Id": "5739abb077801d7f0c102552"
}
],
Your help is greatly appreciated!