I am using the FileReader to parse my csv data and get only the headers. I need to check the headers and do further execution based on the return value.
private checkIfValidFile(file){
var isValidFile = false;
var fileContent = new FileReader();
fileContent.readAsText(file);
fileContent.onload = () => {
let text = fileContent.result;
var data = text.split("\n");
var headers = data[0].split(",");
//fileHeaders = headers;
console.log(headers);
if (headers.indexOf('"File Name"') > -1) {
isValidFile = true;
}
};
return isValidFile
}
private uploadFiles(files: any) {
for (let index = 0; index < files.length; index++) {
var isValidFile = this.checkIfValidFile(files[index]);
if(isValidFile){
//Execute some lines
}
}
}
But the return value gets returned before the onload. How can i do this?