“JS Membaca File Teks Baris demi baris” Kode Jawaban

JS Membaca File Teks Baris demi baris

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);
};
Vast Vendace

JS Membaca File Teks Baris demi baris

handleFiles(input) {

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

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

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

    reader.readAsText(file);
}
Vast Vendace

Jawaban yang mirip dengan “JS Membaca File Teks Baris demi baris”

Pertanyaan yang mirip dengan “JS Membaca File Teks Baris demi baris”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya