Saturday 29 April 2017

(JavaScript) data.split('\n') is not a function

I am trying to make a random string picker with a text document that splits at every line.

However, when I try to run it, it says that data.split is not a function.

fs.readFile('list.txt', function(err, data){
        if(err) throw err;
        var lines = data.split('\n');
        var rand = [Math.floor(Math.random()*lines.length)];
        var rlist = lines[rand]
})



via Revin Bray

No comments:

Post a Comment