Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda