简体   繁体   中英

retrieve data from file, put in an array

I've been trying to figure out the best method for retrieving data from a file and putting it in an array. The final goal is to create a dictionary for a game so that I can validate words that were submitted by a user.

Although I'm still new programming, I've done some research and it seems that .get function may allow that. Before I embark on building all of that code, I wanted to check to see if my starting logic was correct.

If I have a file called wordcheck.txt and it has thousands of words. Can I retrieve the data by

$.get(workcheck.txt, functions(words) {
var wordArray = words.split( "\n");
}

I haven't figured out where to go to from here yet, but I wanted to make sure I was understanding the beginning correctly.

1) Add quotes around the file you're trying to load.

2) You might want to define wordArray before you do the $.get otherwise the data won't be available outside of that anonymous function.

3) It's function not functions .

4) You missed a closing ) .

var wordArray;
$.get('workcheck.txt', function (words) {
  wordArray = words.split('\n');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM