I am fairly new to JS and regular expressions. I was hoping somebody here could help me out with a problem I'm having.
So in my code, what I want to happen is to get an array with each word in the English language in its own index (here's a link to the .txt file I am reading from). So far, I have this:
$(document).ready(function(){
var allWords;
function getAllWords(list) {
$.get("wordlist.txt", function (words) {
var re = "/\w+$/m"
list = words.split(re);
console.log(list);
});
}
getAllWords(allWords);
console.log(allWords);
});
But instead of having each word in its own index, it returns an array with all of the words in one index. Can anybody tell me where I went wrong/point me in the right direction? I can clarify more if needed.
Thanks in advance!