I'm trying to access from an API the values of some currencies, and I'm not managing to get them from within the function.
The API returns after parsing this: {"ETH":{"USD":188.01},"BTC":{"USD":10330.41}}
This is the code I used:
fetch('https://min-api.cryptocompare.com/data/pricemulti?fsyms=ETH,BTC&tsyms=USD')
.then(val => val.json()).then(data => {
info = data; for (var item in data) { console.log(item.USD) }
});
It logs undefined.
When I do in it console.log(item), it logs ETH and BTC as strings and not as objects as they should be.
When I write in the console (outside of .then) info.ETH.USD, I get the results.
What did I get wrong?