I was trying to find out how to get a txt file into javascript when I stumbled across this code:
const fun = async () => {
const response = await fetch(file)
return response.text()
}
const data = fun()
console.log(data)
I tried this code, and it works, but not exactly how I wanted it to. When I output it into the console, it gives me this:
with the .txt
file in PromiseResult
. I want the data
variable to be a string of just PromiseResult
, if that makes any sense. How can I do this? Thank you!
Sorry if some of the terms I use are wrong. I'm very bad at Javascript.
EDIT Btw, this is different from this question, as the code from that question stores the variable in a async function, which makes it a local variable, while I want my variable to be a global variable.