0

I defined an empty variable dataset: var dataset = []; Load data from a .csv file by d3.dsv function, the schema likes

d3.dsv(",", "filename.csv", function(d){
 return {
  key1: value,
  key2: value,
  ...
};
}).then(function(d) {
 //do something like dataset = d to update dataset;
});

My goal is to update the global value dataset I defined at the beginning by .then() function, so I can use the updated dataset later, and it's outside of .then() function. What I can do to achieve my goal?

1 Answers1

-1

You have access to global scope from any other scope

window.dataset = null // define global variable
d3.dsv(",", "filename.csv", function(d){
 return {
  key1: value,
  key2: value,
  ...
};
}).then(function(d) {
 //do something like dataset = d to update dataset;
 window.dataset = d // assign 'd' to 'dataset'
});
varontron
  • 1,120
  • 7
  • 21