I am retrieving two JSON files, DefMenu.json, and customMenuTest.json, processing the data, and then using them to generate menus though a function called generateMenu.
This calls the first file, waits for the data to be returned and processed, writes it to local storage, and invokes the menu generation code.
fetch(defMenuURL)
.then(function(response) {
return response.json();
})
.then(function(defaultMenu) {
defMenu = defaultMenu; //create variable with global scope
localStorage.setItem('defaultMenu',JSON.stringify(defMenu));
generateMenu();
})
How do I fetch the second file, and then ensure that this promise is completed, before invoking generateMenu?