I have to take the first line from my text file and compare to the values from my array. I'm using new FileReader()
to get the first line from my .txt file. Here is my code:
var fileExist = $('#fileUpload')[0];
var reader = new FileReader();
var file = fileExist.files[0];
reader.onload = function(e) {
var text = reader.result;
var firstLine = text.split('\n').shift();
var columnNames = firstLine.split('\t');
console.log(columnNames);
}
reader.readAsText(file, 'UTF-8');
Here is my output:
["LAST_NAME", "FIRST_NAME", "BIRTH_DATE", "GENDER", "PHONE", "EMAIL\r"]
For some reason my last element in the array has \r
. This is the case with any text file that i try to load with this function. How I can get rid of \r
? I tried to include in my split function \r but that did not work, first it looks that all comma's were removed and there is no []
brackets around the text. If anyone can help with this problem please let me know. My text file is tab delimited.