data.txt:
xxxx1;yyyy1
xxxx2;yyyy2
xxxx3;yyyy3
xxxx4;yyyy4
xxxx5;yyyy5
Here is how my data.txt looks like and when I run the following function:
var fs = require('fs');
var x = [];
var y = [];
function pushdata(){
  fs.readFile('data.txt', (err, data) => {
    data = data.toString().split("\n");
    for (let i = 0; i < data.length; i++) {
      x.push(data[i].split(';')[0]);
      y.push(data[i].split(';')[1]);
    }
  });
}
pushdata()
console.log(x, y);
The output is:
[] []
Instead of:
[ 'xxxx1', 'xxxx2', 'xxxx3', 'xxxx4', 'xxxx5' ] [ 'yyyy1', 'yyyy2', 'yyyy3', 'yyyy4', 'yyyy5' ]
What am I doing wrong?
 
    