我有一個csv-reader指令,讓我們用戶上傳一個csv文件。我注意到,當我上傳文件單詞之間的空格,例如:
ABC
ABC
ABC上傳csv文件時刪除空行angular
這被顯示ABC
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
var rows = contents.split('\n');
// Check if the last row is empty. This works
if(rows[rows.length-1] ===''){
rows.pop()
}
}
// this doesn't work for some reason. It doesn't detect the '' in the middle of the arrays.
for(var i=rows.length-1;i>0;i--){
if(rows[i] === ''){
rows.splice(i,1)
}
}
你可能在那裏還有一個\ r char(行不是空的)。 – K3N