Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file which contains a list of words. I would like to open it, read it line by line and save its content as a string list, so that each word becomes an elemetn of thes string list. The I need to shuffle it to randomise the order. Could someone please explain me how to do this with JavaScript? I am very lost and would be very grateful for any help.

What I've tried (see below) opens the file on the server, but I want is a function that opens, reads the file and makes a list in the code. I hope this makes sense.

What I have tried:

<head> 
    <title>Read Text File</title> 
</head> 
  
<body> 
    <input type="file" name="inputfile"
            id="inputfile"> 
    <br> 
   
    <pre id="output">



document.getElementById('inputfile')
.addEventListener('change', function() {

var fr=new FileReader();
fr.onload=function(){
document.getElementById('output')
.textContent=fr.result;
}

fr.readAsText(this.files[0]);
})
Posted
Updated 16-May-21 10:38am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900