I have below code. I only pulls 1 row since I typed [1]
in array. But, there are like 20 rows in that JSON API.
How can I use forEach
loop in this code to get all rows? I greatly appreciate any help.
function getTodos() {
axios
.get('https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v1/accounting/od/rates_of_exchange?fields=country_currency_desc,exchange_rate,record_date&filter=country_currency_desc:in:(Canada-Dollar),record_date:gte:2020-01-20', {
country_currency_desc: 'Currency',
exchange_rate: 'last price',
record_date: 'date',
})
.then((res) => showOutput(res))
.catch((err) => console.log(err))
}
function showOutput(res) {
document.getElementById('row').innerHTML = `
<th>
${JSON.stringify(res.data.data[1].record_date)}
</th>
<th>
${JSON.stringify(res.data.data[1].country_currency_desc)}
</th>
<th>
${JSON.stringify(res.data.data[1].exchange_rate)}
</th>
`
}