Use split("
")
to use newline as the delimiter, not a space.
You don't have to copy the array with the for
loop.
const input = document.querySelector('input[type="file"]');
input.addEventListener(
"change",
function(e) {
const reader = new FileReader();
reader.onload = function() {
const lines = reader.result.split("
");
console.log(lines);
};
reader.readAsText(input.files[0]);
},
false
);
<input type="file">
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…