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

133
Vistas
Get the id of an object in a json request?

So I have to get the first object of this list:

{
"2489": {
    "status": {
        "idstatus": "3",
        "status": "Sold"
    }
},

"2490": {
    "status": {
        "idstatus": "3",
        "status": "Sold"
    }
}

}

I don't know beforehand the IDs ['2489'] and ['2490']. Sometimes it responses only one of these IDs, sometimes 3 or more.

How can I get like ['2490'].status.idstatus without knowing ['2490']?

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

0

There are several ways to do this. If you're running a modern JS environment, you can use Object.keys or Object.values.

Assuming your JSON response object is a variable named res, you can construct a dynamic array of IDs like this:

const ids = Object.keys(res) // ["2489", "2490", ...]

If you don't care about the IDs at all and want an array of all the inner objects, try this:

const items = Object.values(res) // [ { "status" : ... }, ... ]
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can do it using Object.values and map or if you need the key you can use Object.entries

const data = {
"2489": {
    "status": {
        "idstatus": "3",
        "status": "Sold"
    }
},

"2490": {
    "status": {
        "idstatus": "3",
        "status": "Sold"
    }
}
}

const statusIds = Object.values(data).map(d => d.status.idstatus)
console.log(statusIds)

const statusIdAndKey = Object.entries(data).map(([k, d]) => [k, d.status.idstatus])
console.log(statusIdAndKey)

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