javascript: how to parse a FileReader object line by line
I guess you should put
document.getElementById('files').innerHTML = 'Paths with more than 240 characters: <br><ul>' + output.join('') + '</ul>';
inside onload
callback. Seems that output
is not yet populated when you try to use it. So:
reader.onload = function (e) {
// all your code ...
// now can safely print output
document.getElementById('files').innerHTML = 'Paths with more than 240 characters: <br><ul>' + output.join('') + '</ul>';
};
The obvious way (if you can tolerate reading the file all at once) is to split it by newlines.
var lines = text.split(/[\r\n]+/g); // tolerate both Windows and Unix linebreaks
for(var i = 0; i < lines.length; i++) { /* do something with lines[i] */ }
// or in modern JavaScript,
lines.forEach(function(line) { /* ... */ });