为了账号安全,请及时绑定邮箱和手机立即绑定

循环遍历数组内部时如何获取数组的名称?

循环遍历数组内部时如何获取数组的名称?

弑天下 2022-05-22 15:56:55
在数组数组中循环时,我试图获取数组的名称,这里是数组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",           ]      ],我想循环访问角色,并且在每个索引上我想获取该数组中的名称和内容。像,操作:1)2)3)收购:1)2)等等..像这样当我不知道如何获取 Operational 、 Acquisition 之类的名称时,我可以显示每个数组索引中的值。这是我尝试过的。 jobOffer.roles.forEach((role, index) => {       role.forEach(rol => {            roles += `<li style="padding: 8px 0px 8px 0px; color: #000;">${rol}</li>`       })    });任何建议将不胜感激。
查看完整描述

2 回答

?
千巷猫影

TA贡献1829条经验 获得超7个赞

我认为你应该重新格式化你的数组


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",

       ] },

  ],


查看完整回答
反对 回复 2022-05-22
?
呼啦一阵风

TA贡献1802条经验 获得超6个赞

首先,您必须按照@iamhuynq 的建议更改格式。


然后你可以得到这样的钥匙


roles.map(a => {

  console.log(Object.keys(a)[0]) // key

  console.log(a) // object


)

或者你可以改变这样的结构


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",

       ]

};

得到这样的钥匙


Object.keys(roles).map(a => {

  console.log(a) // key

  console.log(roles[a]) // object

})


查看完整回答
反对 回复 2022-05-22
  • 2 回答
  • 0 关注
  • 135 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信