I have a .JSON file, I've read the data and am using a for...in
loop to loop through it.
If I use console.log
, then I can print the data to the console, but if I try to add data to an array using the push function and console.log
the array, I get an empty array.
Basically, how do I add the data to the array?
The code:
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)
Is there something I'm missing?
EDIT: Here is a .txt version of .json file (the text is just in an object in the .json): https://github.com/MissingFable/wordle_bot_4_python/blob/main/wordleanswers.TXT