var info = [];
var data = [];
var ids;
function loadData() {
d3.json('data/res/ID.json', function (error, d) {
ids = d.ids;
d.ids.forEach(function (id, i) {
d3.json('data/res/json/' + id + '.json', function (error, d) {
info.push({
"id": id,
"value": d
})
})
});
initMap(ids, info);
});
}
I simply want to read from several csv files and create an array of object in var info. Then I want to pass the array to a function called initMap(). However, when I console.log(info) in initMap(), it shows an empty array.
I am really confused by the order of the execution of functions. What should to do if I want to make sure that var info is done before passed to initMap()?