I am using fs to read data from a tsv file, but I am not able to access the data anywhere else in the code.
let arr;
fs.readFile('test.tsv', 'utf-8', function read(err, data) {
if (err) {
throw err;
}
arr = data.split('\t');
// Able to print the data here
console.log(arr);
})
// Not able to access the data here
for(const element of arr) {
// rest of the code
}
I just don't want to print the data but also perform certain actions on it. Can anyone please help me out with it? Also, is there any other approach to read the data?