I am trying to fetch a javascript file and return the response object as an array. My javascript file is simply an array like [“1”, “2”, “3”, …] Here is my code right now:
function getNames() {
let data = fetch('/path/to/file')
.then((response) => response.json())
.then(data => {
console.log(data);
return data()
})
.catch(error => {
return error;
});
}
I need to find a way to use the data variable outside of the function. How can I do this?