I'm working on a project with the Fetch API. I'd like to use fetch to get some data out of text files and place them into arrays so I can work with them. I'm not sure what code to use to make the variables global. I thought that by initializing the variable outside of the fetch statement, I might be able to use it that way. Here's what I have so far:
animals.txt
cat
dog
rabbit
index.js
const animalArray;
fetch('animals.txt')
.then((res) => res.text())
.then(data => {
animalArray = data.split(/\r?\n/) //how can I access this outside of the fetch statement?
}
})