I'm trying to insert the elements from this dataset: https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json
into an array. But after the code, when I console.log(arr), the array is still empty.
The console.log inside the for actually works and prints the array, but arr.push doesnt. Why?
let url = "data.json";
var arr = [];
d3.json(url).then(data => {
for(let i = 0; i < data.data.length; i++) {
arr.push(data.data[i]);
console.log(data.data[i]);
}
})
console.log(arr);
<script src="https://d3js.org/d3.v6.min.js"></script>