SOLUTION:
The issue stems from the fact that you are accessing text content via your AJAX request and not a JSON object. The words that ultimately become your property names are being turned into Strings (unlike JSON, where they would be property identifiers). Since you are working with String names, you must use Object.keys()
to access those property names.
The following code demonstrates the differences between an object with properties that are identifiers and your object, which is more of a dictionary that has String names and how to access the dictionary vs. the traditional object.
SpellCheck.txt:
ABCD
ABG
ABI
ABO
AC
ACE
ACEI
ACER
ACL
ADAM
ADHD
ADL
ADPKD
ADS
AENNS
AFB
AFI
AFO
AFP
Your code:
var TextFile = {};
jQuery.get('SpellCheck.txt', function (data) {
var values = data.split('\n');
for (var i = 0; i < values.length; i++) {
var val = values[i];
TextFile[val] = 'true';
}
});
My Tests (Placed INSIDE the AJAX success callback above):
// Test of traditional JS object with properties that are not strings:
var myObj = { prop1: 1, prop2: 2 }
console.log(myObj);
// Test of your dictionary object and how you must use Object.keys()
// to access dictionary elements:
console.log(TextFile);
console.log("Name of first key in dictionary is: " + Object.keys(TextFile)[0]);
console.log("Value of first key in dictionary is: " + TextFile[Object.keys(TextFile)[0]]);
You can see here in the console the difference in how the JS engine sees the two objects:

Notice how your object property names are quoted, but the myObj names aren't?
To get the result you were hoping for, call for a JSON object:
SpellCheck2.txt:
{
"ABCD" : "",
"ABG" : "",
"ABI" : "",
"ABO" : "",
"AC" : "",
"ACE" : "",
"ACEI" : "",
"ACER" : "",
"ACL" : "",
"ADAM" : "",
"ADHD" : "",
"ADL" : "",
"ADPKD" : "",
"ADS" : "",
"AENNS" : "",
"AFB" : "",
"AFI" : "",
"AFO" : "",
"AFP" : ""
}
index.html:
var result = "";
jQuery.get('SpellCheck2.txt', function (data) {
result = JSON.parse(data);
for (var prop in result) {
result[prop] = 'true';
}
console.log("Value of result[\"ABCD\"] is: " + result["ABCD"]);
});
Result: Value of result["ABCD"] is: true