In the below code I take in info from a text file and turn it into an array. Is it standard to then perform all manipulation of the array within this same function or is there some way to bring it out? I plan to rearrange the information in each line of the text file and then download it as a new file. It feels odd to me to put all of this code inside that method, but I don't see a way to bring the array out. Am I correct that I will just have to write the majority of the program inside this function after the reader.readAsText(file) line?
document.getElementById(`file`).onchange = function(event){
let file = this.files[0];
let reader = new FileReader();
reader.onload = function(){
let fileAsArray = this.result.split(`\n`);
console.log(fileAsArray);
for(let i = 0; i < fileAsArray.length; i++){
console.log(fileAsArray[i]);
}
}
reader.readAsText(file);
};