Reputation: 229
i'm trying to get the name of an array when cycling inside the array of arrays,
here the array
roles: [
Operational = [
"Drives cloud standards for adopting cloud services to ensure consistency.",
"Provide regular, clear, and consistent communication (written and oral) on the status of projects, issues, and deliverables to representatives from the customer/vendor.",
"Develop and maintain understanding of key processes, schedules, cycles, profiles, etc. for the technical systems in use by a customer.",
"Work with IT and Business management to evaluate complex user requests, large projects and strategies.",
"Perform analysis of large-scale, complex, cross-system, cross-platform changes or issues.",
],
Acquisition = [
"Work with cloud vendors to evaluate and select services that can support agile business requirements",
"Prepare ROI analysis and assist with creating budget proposals to initiate the acquisition of cloud services",
"Mitigate significant risks associated with large cloud projects, which have a hig",
"complexity and/or involve significant challenges to the business and systems",
"Partner with internal teams and cloud vendors on software and hardware selection and produce and present cost and value benefit analyses",
]
],
I want to cycle through roles and, on each index i want to get the names and content inside that array. Like , Operational : 1) 2) 3) Acquisition : 1) 2) etc.. like so on
I'm able to display the values inside each array index, when no idea how to get the names like Operational , Acquisition to display.
here is what i tried.
jobOffer.roles.forEach((role, index) => {
role.forEach(rol => {
roles += `<li style="padding: 8px 0px 8px 0px; color: #000;">${rol}</li>`
})
});
Any suggestions will greatly appreciated.
Upvotes: 0
Views: 41
Reputation: 728
First you have to change format as @iamhuynq suggested.
Then you can get keys like that
roles.map(a => {
console.log(Object.keys(a)[0]) // key
console.log(a) // object
)
Or you can change structure like that
roles = {
Operational: [
"Drives cloud standards for adopting cloud services to ensure consistency.",
"Provide regular, clear, and consistent communication (written and oral) on the status of projects, issues, and deliverables to representatives from the customer/vendor.",
"Develop and maintain understanding of key processes, schedules, cycles, profiles, etc. for the technical systems in use by a customer.",
"Work with IT and Business management to evaluate complex user requests, large projects and strategies.",
"Perform analysis of large-scale, complex, cross-system, cross-platform changes or issues.",
],
Acquisition: [
"Work with cloud vendors to evaluate and select services that can support agile business requirements",
"Prepare ROI analysis and assist with creating budget proposals to initiate the acquisition of cloud services",
"Mitigate significant risks associated with large cloud projects, which have a hig",
"complexity and/or involve significant challenges to the business and systems",
"Partner with internal teams and cloud vendors on software and hardware selection and produce and present cost and value benefit analyses",
]
};
And get keys like that
Object.keys(roles).map(a => {
console.log(a) // key
console.log(roles[a]) // object
})
Thanks
Upvotes: 0
Reputation: 5539
I think you should re-format your array
roles: [
{ Operational: [
"Drives cloud standards for adopting cloud services to ensure consistency.",
"Provide regular, clear, and consistent communication (written and oral) on the status of projects, issues, and deliverables to representatives from the customer/vendor.",
"Develop and maintain understanding of key processes, schedules, cycles, profiles, etc. for the technical systems in use by a customer.",
"Work with IT and Business management to evaluate complex user requests, large projects and strategies.",
"Perform analysis of large-scale, complex, cross-system, cross-platform changes or issues.",
] },
{ Acquisition: [
"Work with cloud vendors to evaluate and select services that can support agile business requirements",
"Prepare ROI analysis and assist with creating budget proposals to initiate the acquisition of cloud services",
"Mitigate significant risks associated with large cloud projects, which have a hig",
"complexity and/or involve significant challenges to the business and systems",
"Partner with internal teams and cloud vendors on software and hardware selection and produce and present cost and value benefit analyses",
] },
],
Upvotes: 1