I have a simple string and i split it into an array:
var alphabet = "a,b,c,d,e";
var letters = alphabet.split(",");
var dict = [];
for ( var i = 0; i < letters.length; i++ ) {
dict[ letters[i] ] = true;
}
What stumps me is that when i do a
console.log(dict[letters[0]] +"|"+ dict["a"]);
I get
//true|undefined
I dont understand the difference between letters[0] and "a". And i'm absolutely sure that letters[0] and "a" are both type of string.
EDIT: I just tried changing variable "dict" from the square brackets to the curly ones but it still gives me undefined.
EDIT 2: The below code is what im working with. "dictionary.txt" is a text file containing some 90k words separated by "\n". In this text file, the letter "a" is on the first line.
$.get( "tiles/dictionary.txt", function( txt ) {
// Get an array of all the words
var words = txt.split( "\n" );
// And add them as properties to the dictionary lookup
// This will allow for fast lookups later
for ( var i = 0; i < words.length; i++ ) {
dict[ words[i] ] = true;
}
console.log(dict[words[0]]+"|"+dict["a"]);
});
Maybe i should have just started out with this, instead of trying to make a simplified version of it.
a. Perhaps there is whitespace besides the newline?console.log(words[0] == "a")