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

180
Vistas
Get a value from an object inside an object

How do I get the id 43 from country ?

"hq_locations":[{"id":1886112,"address":"10 Rue Laurencin, 69002 Lyon, France","street":"Rue Laurencin","street_number":"10","zip":"69002","lat":45.7527311,"lon":4.8321804,"country":{"id":43,"name":"France","lat":46.227638,"lon":2.213749,"trade_register_office":"Info Greffe"}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The reason why it is probably not working is because the hq_locations contains an array that contains an object that contains a child object and some properties.

As you can see the levels you have to bypass before you get to the id of the country is more than just selecting the object in the object and then its property.

An example to access the first element in the row:

const obj = {
    "hq_locations": [{
        "id": 1886112,
        "address": "10 Rue Laurencin, 69002 Lyon, France",
        "street": "Rue Laurencin",
        "street_number": "10",
        "zip": "69002",
        "lat": 45.7527311,
        "lon": 4.8321804,
        "country": {
            "id": 43,
            "name": "France",
            "lat": 46.227638,
            "lon": 2.213749,
            "trade_register_office": "Info Greffe"
        }
    }]
};

console.log(obj.hq_locations[0].country.id)

If you want to access all the elements in the array and select all the ids you'd have to loop it:

   for (let i = 0; i < obj.hq_locations.length; i++) {
    console.log(obj.hq_locations[i].id)
}
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