Javascript help does anyone understand this?

saintsfan0990

Commendable
Jun 18, 2016
3
0
1,510
0
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">
 
Thread starter Similar threads Forum Replies Date
F Apps General Discussion 0
T Apps General Discussion 5
A Apps General Discussion 2
S Apps General Discussion 1
anustarique Apps General Discussion 3
alanps Apps General Discussion 3
D Apps General Discussion 1
R Apps General Discussion 1
V Apps General Discussion 4
The_Freeman Apps General Discussion 11
E Apps General Discussion 3
viveknayyar007 Apps General Discussion 0
ivideo1011 Apps General Discussion 7
Orogi Apps General Discussion 6
R Apps General Discussion 1
S Apps General Discussion 1
S Apps General Discussion 11
C Apps General Discussion 9
jappe66 Apps General Discussion 4
R Apps General Discussion 1

ASK THE COMMUNITY