Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
how to foreach the object key in javascript

I define a object like this using Javacript:

const city = {
  "北京市": ["北京市"],
  "天津市": ["天津市"],
  "上海市": ["上海市"],
  "重庆市": ["重庆市"],
  "香港": ["香港"],
  "澳门": ["澳门"],
  "台湾省": ["台湾省"]
};

now I want to foreach the city key with other strings I defined like this:

const region = [
  "北京市",
  "天津市",
];

but I did not know how to foreach the key of city, what I want to do may look like this:

var options = region.map(function (item){
    
     children = city.map(function (itemc){
       if(itemc.key === item){
         return itemc.value
       }
     });
      return ({
        label: item,
        children: children
      });
    });

but the city did not contains keys or index for me to compare, what should I do to make it work?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda