I have a small function, that should get json data from a response.
<code>function kGetExchangeRates() {
const apiUrl = 'my api link';
return fetch(apiUrl).then(response => response.json())
}
</code>
<code>function kGetExchangeRates() {
const apiUrl = 'my api link';
return fetch(apiUrl).then(response => response.json())
}
</code>
function kGetExchangeRates() {
const apiUrl = 'my api link';
return fetch(apiUrl).then(response => response.json())
}
If i use it from browser console e.g.
<code>let rates = {};
kGetExchangeRates().then(e => rates = e.rates);
rates
</code>
<code>let rates = {};
kGetExchangeRates().then(e => rates = e.rates);
rates
</code>
let rates = {};
kGetExchangeRates().then(e => rates = e.rates);
rates
everything seems to work fine and i get an object i need. But if i put this code into another function
<code>function kCalculatePay(){
let rates = {};
kGetExchangeRates().then(e => rates = e.rates);
}
</code>
<code>function kCalculatePay(){
let rates = {};
kGetExchangeRates().then(e => rates = e.rates);
}
</code>
function kCalculatePay(){
let rates = {};
kGetExchangeRates().then(e => rates = e.rates);
}
My rates variable seem to be empty. I’ve read tons of topics with same issue, but still don’t understand what i’m doing wrong. I just need a key: value array on function call. How i do So?
0