I'm writing a program that gives me random song names I've input into a text file. Here's the code I have so far:
var fs = require('fs'),
    path = require('path');
fs.readFile('names.txt', 'utf8', function(err, data) {
    var arr = data.toString().split('\n'),
        names = [];
    for (var i in arr) {
        if (arr[i].length !== 0) {
            names.push(arr[i].trim());
        }
    }
    console.log(names[1]);
});
I've noticed that whenever I put an odd number into the console.log() statement it returns the empty newline / whitespace. How can I fix this or remove it? Thanks for any help!
 
     
     
     
    