0

So I'm running this code from a node console and I need to put the result as a variable

 var csv = require('csv-array');
 csv.parseCSV("my.csv"
 , function(data){
   console.log(JSON.stringify(data));
 });

The array prints out fine, but how do I set the result as a variable? (I'm hoping this is as easy as it seems for someone with experience)

thefett
  • 280
  • 2
  • 8
  • I'm not big on this whole js thing, care to elaborate? If you put it as an answer, you can grab an easy correct – thefett Sep 10 '17 at 01:03

1 Answers1

1

Here you go,

 var csv = require('csv-array');
 //variable declaration
 var myVariable;
 csv.parseCSV("my.csv", function(data){
   myVariable = JSON.stringify(data);
   return data;
 });
 //take it as a variable here.
 console.log(myVariable);
Ahmed Can Unbay
  • 2,694
  • 2
  • 16
  • 33