I am facing an issue with my array containing 58112 words. Whenever I try to check if a word is in the list, it always returns false, except for the first word. While I cannot share my entire code due to its length, here are the key details:
isWord("a") //true
isWord("hello") //false??
function isWord(word) {
word = word.toLowerCase();
for (let i = 0; i < words.length; i++) {
if (word == words[i]) {
return true;
} else {
return false;
}
}
}
words[]
represents the list of 58112 words, with the initial word being "a". When I use isWord("a")
, it correctly returns true. However, for any word other than "a", it returns false. What could be causing this behavior? Could it be related to exceeding the maximum array limit? I doubt that is the case.
The words used are sourced from this source (I had to manually add "a" and "i" since they were missing).