Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

0

You can use the bracket-notation:

JSON.parse(this.$store.state.clientSide.currencyrates).rates[new_currency]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!