title: Read CSV with d3 (v3 or v4), save data and callback
body: <p>I am using d3js v4 to bring and read a csv file. I am not using any frameworks. Simply using it like it shows here: <a href="https://github.com/d3/d3-fetch/blob/master/README.md#csv" rel="nofollow noreferrer">https://github.com/d3/d3-fetch/blob/master/README.md#csv</a></p>
  
  <p>I notice that in all examples they just send it to console. log and I really need to keep the data stored in the object. </p>
  
  <p>If I do console.log() in the callback it prints them, so I know it is reading the file and bringing the data, but even if I create a variable inside, or I use a variable brought from 'this', or copy the values into an object, it all fails. This is not because of the asynchronicity because the file is read and it works, then it goes out of scope. I need it to be saved out of the scope of the d3.csv.</p>
  
  <p>A simple version of the code with two options to try and copy the parsed CSV object.</p>
  
  <pre><code>containerobject = {
      readCSV: function (astring, thecsv) {
          console.log(astring); 
          console.log(thecsv);
          var answer; //I want to store the parsed csv here
          var request = d3.csv(
              thecsv,
              function (d) {
                  return {
                      name: d.name,
                      x: Number(d.x),
                      y: Number(d.y)
                  };
              },
              function (rows) {
                  if (rows === undefined || rows === null) {
                      alert('error');
                  }
                  if (astring == "one") {
                      answer = d3.nest()
                          .key(function (d) { return d.letters; })
                          .entries(rows); //console.log(answer); This prints
                  } else if (astring == "two") {
                      answer = Object.assign({},(function(){ return d3.nest()
                          .key(function (d) { return d.letters; })
                          .entries(rows);}())); //console.log(answer); This prints
                  }
              }
          );
          console.log("answer", answer); // this is undefined
          return answer;
      }
  }
  </code></pre>
  
  <p>Note: As sometimes it happens, it was all working recently and now it just doesn't.</p>
  
  <p>Thank you all</p>