0

I'm trying to create a web app where I have some sort of a flash card, but the information of the flash card will be coming from a .txt file I created.

I'd like to be able to read each line as it's own question or array, and then have the answer for that question in another .txt file that will match the same line so I can use the same index value.

I'm sorry if it sounds confusing. I am just getting started on the idea.

Thank you.

  • take a look at the accepted answer of this question: https://stackoverflow.com/questions/14446447/how-to-read-a-local-text-file – JavaMan Nov 07 '20 at 13:08

1 Answers1

0

Use one of the examples in MDN - Using files from web applications to get the file you want to process. Once you have selected your file, you can use a FileReader.readAsText() to get the full text of the file as a string.

let myArray;

let fileReader = new FileReader();

fileReader.onload = (event) => {
   myArray = event.target.result.split('\n');
}

fileReader.readAsText(myFile);

Take a deep read on the first article. It has lots of examples of working with files. It has helped me a lot

PS: if it worked, please, mark this as the solution. I need reputation to be able to comment ^_^

RDM
  • 56
  • 8