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

196
Vistas
can I pick a grandchild value directly in object without being through parent value?

I need to pick up value from a returned API object, the hierarchy is like this

{"name":
       {"common":"Germany",
        "official":"Federal Republic of Germany",
        "nativeName":
             {"deu":
                {"official":"Bundesrepublik Deutschland",
                 "common":"Deutschland"}}},
  "currencies":
        {"EUR":
             {"name":"Euro",
              "symbol":"€"}}

I want to pick up "Deutschland", so I write like name.nativeName.deu.common , but the problem is by each different user input, the country name changes each time, and "deu" and "EUR" also will be different, in this example, is that a way that I can pick up the value "common" under "nativeName" and "name" under "currencies", without going through their parents "deu" and "EUR"?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

It looks like the API may return a response with multiple keys on both nativeName and currencies, so here's an example that returns all values as array.

const apiResponse = {
  "name": {
    "common": "Germany",
    "official": "Federal Republic of Germany",
    "nativeName": {
      "deu": {
        "official": "Bundesrepublik Deutschland",
        "common": "Deutschland"
      }
    }
  },
  "currencies": {
    "EUR": {
      "name": "Euro",
      "symbol": "€"
    }
  }
}

const nativeNames = Object.keys(apiResponse.name.nativeName).map(key => {
  return apiResponse.name.nativeName[key].common;
});

const currencies = Object.keys(apiResponse.currencies).map(key => {
  return apiResponse.currencies[key].name;
});

console.log(nativeNames);
console.log(currencies);

about 4 years ago · Santiago Gelvez 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