Javascript help does anyone understand this?

saintsfan0990

Commendable
Jun 18, 2016
3
0
1,510
So, I have been working with javascript. I was looking up how to read a txt file line by line using javascript and came across this answer. Can anyone explain how this works line by line?


Without jQuery:

document.getElementById('file').onchange = function(){

var file = this.files[0];

var reader = new FileReader();
reader.onload = function(progressEvent){
// Entire file
console.log(this.result);

// By lines
var lines = this.result.split('\n');
for(var line = 0; line < lines.length; line++){
console.log(lines[line]);
}
};
reader.readAsText(file);
};

HTML:
<input type="file" name="file" id="file">