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

178
Vistas
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 Respuestas
Responde la pregunta

0

You can use the bracket-notation:

JSON.parse(this.$store.state.clientSide.currencyrates).rates[new_currency]
about 4 years ago · Juan Pablo Isaza 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