I am really new to learning ES6 and JQuery so apologies if I am asking an already duplicated question (didnt find similar questions)
I am currently trying to get the data from the JSON file to work as the following
{
EUR: { code: "EUR", symbol: "€", rate: "5,278.0518", … }
GBP: { code: "GBP", symbol: "£", rate: "4,640.1577", … }
USD: { code: "USD", symbol: "$", rate: "6,152.3500", … }
}
Here's the code I have so far:
class App extends Component {
constructor(props){
super(props)
this.state = {}
this.performSearch()
}
performSearch(){
const urlString = "https://api.coindesk.com/v1/bpi/currentprice.json";
$.ajax({
dataType: 'json',
url: urlString,
success: data => {
console.log("This is in my data", data["bpi"])
}
})
}
render() {
return (
<div className="App">
<p>This is a testing p</p>
</div>
);
}
}
I want to iterate over my data["bpi"] so that I can iterate over all the keys and values in the dictionary.
However, because the dataType of data["bpi"] is undefined, I cannot use the forEach() method on here.
So how should I approach this without having to hard-code everything? (i.e. it works when I do console.log(data["bpi"]["EUR"]))
Thanks for your help