I have this piece of code done in Javascript, where I want to save the name of colleges from an csv file to an array named results. Although I can print values while I am inside the function the array is empty when I print it out of the function.
const csv = require('csv-parser')
const fs = require('fs')
var results = [];
fs.createReadStream('final.csv')
.pipe(csv())
.on('data', (data) => results.push(data['']))
.on('end', () => {
console.log(results);
// Output -> [ 'Cochise County Community College District', 'Empire Beauty School-Flagstaff',....]
});
console.log("List: "+results); //It prints [](empty array) here though