I\'m loading a CSV of a list of other CSV files into javascript using D3.
When I run the following code, the employees array is still empty by the time it gets
You could use queue.js to collect the results from all the d3.csv calls:
function parseList(filenames){
var q = queue();
filenames.forEach(function(d) {
//add your csv call to the queue
q.defer(function(callback) {
d3.csv(d.filename,function(res) { callback(null, res) });
});
});
q.await(restOfCode)
}
function restOfCode(err, results) {
//results is an array of each of your csv results
console.log(results)
}
Your code seems fine. It's just that you're logging employees
before the data is ready. But if you console.log
it on the last line of parseList
you should have it.