I have a problem with my API call. When I return my data I get a empty array with data. This is my code from call the API.
function HeadQuartersGet() {
var data = [];
async function fetchData() {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
var json = await fetch(url, requestOptions)
.then((response) => {
return response.json();
})
.then((result) => {
console.log(result);
});
data = JSON.stringify(json);
}
fetchData();
console.log(data);
return [data];
};
My data log is empty. What I need to do to get data from the result because result log has my data.