How can I retrieve the data from the second object's tts number (1,152.81) and display it correctly?
I attempted to use priceTag.innerHTML = data[0].tts in my javascript file below, but it doesn't seem to be working as expected. Can you help me figure out how to access that specific data?
const url = "https://www.koreaexim.go.kr/site/program/financial/exchangeJSON?authkey=KiGkSEG4nhXCrQ0PioaqVQJDb0lEfKeE&data=AP01"
const priceTag = document.querySelector("h1")
// fetch data
const checkPrice = function() {
fetch(url)
.then(response => response.json())
.then(data => {
priceTag.innerHTML = data[0].tts
})
}
checkPrice()
The JSON file contains a total of 22 objects, but I have only included 2 of them for reference.
[
{
"result": 1,
"cur_unit": "THB",
"ttb": "35.42",
"tts": "36.13",
"deal_bas_r": "35.78",
"bkpr": "35",
"yy_efee_r": "0",
"ten_dd_efee_r": "0",
"kftc_bkpr": "35",
"kftc_deal_bas_r": "35.78",
},
{
"result": 1,
"cur_unit": "USD",
"ttb": "1,129.98",
"tts": "1,152.81",
"deal_bas_r": "1,141.4",
"bkpr": "1,141",
"yy_efee_r": "0",
"ten_dd_efee_r": "0",
"kftc_bkpr": "1,141",
"kftc_deal_bas_r": "1,141.4",
}
]