Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js read text file line by line

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('
');
    for(var line = 0; line < lines.length; line++){
      console.log(lines[line]);
    }
  };
  reader.readAsText(file);
};
Comment

js read text file line by line

handleFiles(input) {

    const file = input.target.files[0];
    const reader = new FileReader();

    reader.onload = (event) => {
        const file = event.target.result;
        const allLines = file.split(/
|
/);
        // Reading line by line
        allLines.forEach((line) => {
            console.log(line);
        });
    };

    reader.onerror = (event) => {
        alert(event.target.error.name);
    };

    reader.readAsText(file);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: StatusBar 
Javascript :: math ceil 
Javascript :: json data sample 
Javascript :: how to delete file from firebase storage on web 
Javascript :: not in array js 
Javascript :: convert to 24 hours format javasript 
Javascript :: javascript create array with null values 
Javascript :: jquery hover and hover out 
Javascript :: jquery on wheel event 
Javascript :: javascript change color of text input 
Javascript :: replace all js 
Javascript :: bootstrap datepicker options 
Javascript :: javas script add list 
Javascript :: linear gradient css react js 
Javascript :: useparams example 
Javascript :: redis nodejs 
Javascript :: how to change package name in ios react native 
Javascript :: json limit nodejs 
Javascript :: json update pytohn 
Javascript :: jqueyr element is hide 
Javascript :: angular download image base64 
Javascript :: remove id attribute javascript 
Javascript :: ifsc code yup validation 
Javascript :: react bootstrap carousel caption placement top 
Javascript :: simple kick command discord.js v12 
Javascript :: remove classname to node 
Javascript :: or inside if javascript 
Javascript :: discord client.send_message js 
Javascript :: email regex pattern input css 
Javascript :: react antd form disable submit button 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =