Hey there, im pretty new to javscript and i was fooling around with this module. Does anyone has an idea why i wont get any output from the "output" array in my second for-loop. When i put this loop into the lr.on('end') function it will work, but thats not what i want.
I would like to use the line-by-line reader to fill an array with the lines and then use it elsewhere, is that not possible?
const LineByLineReader = require('line-by-line');
const path = require('path');
document.getElementById("inputFile").addEventListener("change", parseFiles);
function parseFiles(evt) {
var files = evt.target.files;
var output = [];
for (var i = 0, f; f = files[i]; i++) {
var lr = new LineByLineReader(path.join(__dirname,'/txtFile/',files[i].name))
lr.on('error', function (err) {
console.log(err);
});
lr.on('line', function (line) {
output.push(line);
console.log(line)
});
lr.on('end', function () {
// if i'd put it here it would work
});
};
//not working
for (var k = 0; k < output.length; k++){
console.log(k)
document.getElementById('output').innerHTML += `<li class="list-group-item"> ${output[k]} </li>`;
}
};