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

224
Visualizações
Is there some sort of wildcard when fetching data?

I want to display the name of the currency of different countries. To do this I use an API and fetch the json in my JS file.

this is the json response file I get calling Brazil

This is the json response file I get calling USA

The problem is the different names. In this case "BRL" oder "USD" to enter the names of the currencies.

my code to call the name of brazils currency

In this case I used "BRL", but I want to be able to enter every different countries currency element. I would think that I would need some sort of wildcard.

Maybe some of you can help me on how to handle this problem.

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

0

I actually found out that there is an older version of the API in which the currency is display a lot simplier. That way I can access the currencies of each country easier.

In the older version the json for USA´s currency for example would look like this

That way I dont actually need to enter the different kinds of currencies first, when fetching the data.

about 4 years ago · Juan Pablo Isaza Relatório

0

you can do it more simple way

document.querySelector("#currency").innerHTML = 
                          Object.values(data[0].currencies)[0].name;

or maybe this if you want to show several properties

function displayCountry(data) {
  data.forEach((item) => {
    Object.keys(item.currencies).forEach((key) => {
      document.querySelector("#currency").innerHTML = item.currencies[key].name;
    });
  });
};
about 4 years ago · Juan Pablo Isaza Relatório

0

If you are calling the API with a currency abbreviation like "USD" and "BRL", then you can put those into an array like this:

const arrayOfCurrencies = ["USD", "BRL", ...];

When you are displaying them to the DOM, you can use those values as dynamic properties of the response like so:

for(let abbr of arrayOfCurrencies) {
  document.querySelector("#currency").innerHTML = data[0].currencies?.[abbr]?.name ?? fallbackString;
}
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