Javascript 在数组的内部循环时,如何获取数组的名称?

Javascript 在数组的内部循环时,如何获取数组的名称?,javascript,arrays,Javascript,Arrays,在数组中循环时,我试图获取数组的名称 这里是数组 roles: [ Operational = [ "Drives cloud standards for adopting cloud services to ensure consistency.", "Provide regular, clear, and consistent communication (written and oral) on the stat

在数组中循环时,我试图获取数组的名称

这里是数组

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) 等诸如此类

我能够显示每个数组索引中的值,而不知道如何显示操作、采集等名称

这是我试过的

 jobOffer.roles.forEach((role, index) => {
       role.forEach(rol => {
            roles += `<li style="padding: 8px 0px 8px 0px; color: #000;">${rol}</li>`
       })
    });
jobOffer.roles.forEach((角色,索引)=>{
role.forEach(rol=>{
角色+=`
  • ${rol}
  • ` }) });

    任何建议都将不胜感激。

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

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

    首先,您必须按照@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
    })
    
    或者你可以这样改变结构

    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
    })
    
    拿到这样的钥匙

    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
    })
    

    谢谢

    您能提供一个片段来获取值吗?您可以在控制台中看到