Jump to content

Extracting values from json objects


simplest

Recommended Posts

Hi,

I have just starting doing react and I have the following function which pass 4 values to the API to obtain data objects.

let ratesData = getRatesFromDates(startDateRate, endDateRate, baseCurrency, targetCurrency);
  async function getRatesFromDates(startDate, endDate, baseCurrency, targetCurrency) {
    try {
      let response = await fetch('https://api.exchangeratesapi.io/history?start_at=' +
                                    startDate + '&end_at=' + endDate + '&symbols=' + baseCurrency + ',' + targetCurrency);
      let jsonData = await response.json();
      return jsonData.rates;
     } catch(error) {
      console.error(error);
    }
  }
  console.log(ratesData);

In console, these are the data obtained.

image.png.1ab2d922e9cdb6b0d2a146d4f098c84a.png

I am wondering how I can loop through these data to make use and display them on the webpage or pass certain values to other functions?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...