I want to read a json file but when I use await it seems to not wait for the file to get into the var
I have this code:
var webshopItems;
window.addEventListener('load', Initieer);
function Initieer() {
ReadJSON();
console.log(webshopItems[0].Name)
};
const ReadJSON = () => {
let path = 'js/webshopItems.json';
(async () => {
webshopItems = await(GetJSON(path));
})()
}
const GetJSON = async (file) => {
let response = await fetch(file);
let data = await response.json();
return data;
}
So when I try this code webshopItems is undefined when i try to get the name. The name is correct because if i debug at somepoint it will get loaded just not in time.