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

104
Views
Open Exchange Rates issue to define currency from variable

I am fetching a specific currency exchange rate on a specific date through the API in javascript. My code goes like:

 var currency = 'KWD';
 var date = '2022-01-01';
 $.get('https://openexchangerates.org/api/historical/' + date + '.json', {app_id: 'XXXXXXXXXXX'}, function(data) {
alert("On " + date + ", 1 US Dollar was worth " + data.rates.currency + " "+currency);
           });

all works well if I specify the final currency in my code:

 $.get('https://openexchangerates.org/api/historical/' + date + '.json', {app_id: 'XXXXXXXXXXX'}, function(data) {
alert("On " + date + ", 1 US Dollar was worth " + data.rates.KWD + " "+currency);
           });

but i need to fetch the currency from variable currency. any help on this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As Shreshth stated in a comment above, you can use square brackets to access object properties from a variable's content.

For example...

$.get('https://openexchangerates.org/api/historical/' + date + '.json', {app_id: 'XXXXXXXXXXX'}, function(data) {
    alert("On " + date + ", 1 US Dollar was worth " + data.rates[currency] + " "+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!