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

284
Visualizações
JavaScript Nested Object data access

code I'm using to access dataenter image description herethe picture includes country data from country rest API currencies: USD: name: "United States dollar" symbol: "$"

In this situation, the keyword USD is different for each country, in that case how to access that USD and properties inside it(name, symbol) through currencies property. let currencies = { usd: { name: ' ', symbol: ' ' } }; I used this line to declare variable but this line will update usd for all the countries.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

We didn't get a full example but I assume you have something like this. This might explain how to access these values

const data = [
  {
    country: "United States",
    currencies: {
      usd: {
        name: "US Dollar",
        symbol: "$",
      },
    },
  },
  {
    country: "England",
    currencies: {
      usd: {
        name: "Sterling Pound",
        symbol: "£",
      },
    },
  },
  {
    country: "Germany",
    currencies: {
      usd: {
        name: "Euro",
        symbol: "€",
      },
    },
  },
];

First you need to get property you're trying to destructure, let's say the country you're trying to access is the US.

const selectedCountryData = data.find((val) => val.country === "United States");

And then simply extract values by destructuring

const { currencies: { usd:{ name, symbol } } } = selectedCountryData;
about 4 years ago · Juan Pablo Isaza 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