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

177
Visualizações
Appending a string to a json parse returns a string literal

I have some currencies i have saved inside the state manager of my app and this is how i am calling it:

For instance, to get the value of Euro against dollar, i

JSON.parse(this.$store.state.clientSide.currencyrates).rates.EURO

I am getting the currency from a click event and once i acquire the currency symbol, i am passing it to the statement above to fetch me the exchange rate

let currency = e.currentTarget.getAttribute('currency');
let new_currency = currency.toUpperCase();
var state_fx = JSON.parse(this.$store.state.clientSide.currencyrates).rates.`${new_currency}`;
this.$store.commit('setCurrency', new_currency);
alert('state fx'+state_fx);

i was expecting alert() to show me the numeric value of the exchange rate but instead i get a long string of JSON.parse(this.$store.state.clientSide.currencyrates).rates.INR when i try getting the rupee exchange rate.

Doing this

var state_fx = "JSON.parse(this.$store.state.clientSide.currencyrates).rates."+new_currency;

produces same result. How can i pass the currency symbol safely so that i return the exchange rate?

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

0

You can use the bracket-notation:

JSON.parse(this.$store.state.clientSide.currencyrates).rates[new_currency]
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