title: How do I declare an array from a function globally?
body: <p>I am trying to declare an array from the function globally so that my other functions can use it as well but I have no idea how to since I am using a csvtojson for converter which makes the whole thing very long and was wondering if this is the way to declare or no?</p>
  
  <p>JS:</p>
  
  <pre><code>//require the csvtojson converter class 
  var Converter = require("csvtojson").Converter;
   // create a new converter object
  var converter = new Converter({});
  var MongoClient = require('mongodb').MongoClient;
  var url = 'mongodb://localhost:27017/myproject';
  
  // call the fromFile function which takes in the path to your 
  // csv file as well as a callback function
  var JSarray = converter.fromFile("./NTA-SAM-Inventory-List-Security-
  Management-New_2017.csv",function(err, result, callback){
  if(err){
      console.log("An Error Has Occured");
      console.log(err);  
  } 
  // the result of the conversion
  console.log(result);
  result.toArray(function(err,doc){
      if(err) throw err;
      console.log('ohhhhh');
      return callback(null, doc);
  }
  });
  </code></pre>
  
  <p><code>var array=[JSarray(function(err,doc)]</code> This is how I declare the array.
  My array is doc and so I can return callback but how should I get the array considering I have <code>converter.fromFile("./NTA-SAM-Inventory-List-Security-
      Management-New_2017.csv"</code> which is too long so do I omit it when declaring the array or am I doing it wrong ? Thanks.</p>
  
  <p><strong>Update</strong>
   Just wanted to clarify if I did it correctly.</p>
  
  <pre><code>var JSarray = converter.fromFile("./NTA-SAM-Inventory-List-Security-M 
  anagement-New_2017.csv",function(err, result, callback){
  // if an error has occured then handle it
  if(err){
      console.log("An Error Has Occured");
      console.log(err);  
  } 
  // the result of the conversion
  console.log(result);
  result.toArray(function(err,doc){
      if(err) throw err;
      console.log('ohhhhh');
      return callback(null, doc);
      var myArray= doc;
      GLOBAL.GlobalMyArray = myArray;
  });
  });
  </code></pre>
  
  <p>Is this correct following your answer in declaring it globally?</p>