I have an Array object that looks like this:
var wordList = new Array();
$.get('words.txt', function(data){
wordList = data.split('\n');
});
When I do this:
return jQuery.inArray(word, wordList)!==-1;
Using a word that I //know// is in the array, it'll still return false. It might be that the array is too large (it contains 173,139 strings) - is this it? In this case, should I give up on using an array, or is there a different way to go about searching the array?
I checked the type of the word and the elements in the array - both are string according to JavaScript's typeof
.
What's odd is that I've used inArray with the same words and a different array, and it works just fine - the difference is the way the arrays are generated (one is through the same input I get word
from, and one is by splitting lines in a .txt file).
Also, when I try to call the element explicitly by its index, it shows up, so I'm sure the array is loading in. I'm using high index numbers too; calling wordList[173138] doesn't make the response time slow in any way.
Why isn't inArray() working here?