letsjustbereal Posted August 13, 2015 Share Posted August 13, 2015 Hello, I want to create a RandomWord program in JavaScript. You click on the screen and a new random word appear on screen. For this I need a complete list of all English words (which I have). Now the most stupid idea would be to copy all those words into a file, and putting everything into an array and access the array with Math.random.. but it would take AGES to format every word to fit my criteria... Is there a way to neatly access the file, which is just a list of words each one on a new line and get the words out? Thanks a lot, ForR Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2015 Share Posted August 13, 2015 If it's just one word per line you can use String.split to split it into an array of lines. Link to comment Share on other sites More sharing options...
letsjustbereal Posted August 13, 2015 Author Share Posted August 13, 2015 and then use new line as separator. thanks!!! Link to comment Share on other sites More sharing options...
letsjustbereal Posted August 13, 2015 Author Share Posted August 13, 2015 it turns out it's not trivial to detect line breaks.. is there an easy way that you guys know that i can steal? Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2015 Share Posted August 13, 2015 What do you mean? There are only a few different kind of line breaks. I would suggest saving the file using a specific line break character and then splitting on that. Unix-style line endings are probably the most common. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now