I use fetch
to load json
data which works fines. I am trying to return that data back to another function but I am getting undefined
. It should be a simple return
because the data is there. Am I doing something wrong inside the then
?
The console.log(data);
displays that data fine. However console.log(gameData);
gives me an undefined
(function loadGameData () {
var gameData = loadData('assets/gameData.json');
console.log(gameData);
})();
function loadData(json) {
fetch(json)
.then(response => response.json())
.then(data => {
console.log(data);
return(data);
});
}