I am currently working with a .JSON file where I have read the data and implemented a for...in
loop to iterate through it.
After using console.log
, I noticed that while I can view the data in the console, I am unable to add any data to an array using the push function. When I try to log the array, it appears empty.
My main question is: how can I successfully add the data to the array?
Below is the code snippet:
let wordList = []
fetch("wordleanswers.json")
.then(response =>response.json())
.then(data=>{
let myWord = data.toString()
for (const singleData in data){
wordList.push(singleData)
}
})
console.log(wordList)
I'm wondering if there is something crucial that I might be overlooking?
EDIT: In case it helps, here is a .txt version of the .json file containing the text within an object: https://github.com/MissingFable/wordle_bot_4_python/blob/main/wordleanswers.TXT