Download this
dictionary file
and upload it to your project.
Fetch the dictionary file, and save it in a dictionary variable
// make an empty dictionary variable
let dictionary = {}
// fetch the dictionary file
let request = new XMLHttpRequest()
request.addEventListener(`load`, makeDictionary)
request.open(`GET`, `dictionary.txt`)
request.send()
// this function gets called after fetching the dictionary file
function makeDictionary() {
// get all of the words in the file and save it to an array
let words = this.response.split(/\r?\n/)
// loop through the array of words
for (let word of words) {
// save each word in the dictionary variable
dictionary[word] = true
}
}
Use the dictionary variable where you want to determine if a word is an
actual word
if (dictionary[word]) {
// word is an actual word
}