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

154
Vistas
How to iterate JSON object with same key

I have a API response, which is like the below code

const res = {

"a" : {},
"a" : {}

}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This is not possible. In JSON, there is no error if you use the same name for multiple keys, but the last key with the same name will be used. I suggest using an array for the values for a key.

E.g.:

const res = {
    "a" : {},
    "a" : {}
}

would be

const res = {
    "a" : [{}, {}]
}

Then you could iterate on the list.

about 4 years ago · Juan Pablo Isaza Denunciar

0

if "a" isn't used to identify it's value, it shouldn't be a key. You could restructure you JSON to look like this:

const res = [
  ["a", {}],
  ["a", {}]
]

and then iterate over it using:

for(let [k,v] of res)
  print(k,v)
about 4 years ago · Juan Pablo Isaza Denunciar
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