Skip to content
Advertisement

How do I wait for the function to complete?

JavaScript

json/shortcuts.json file is:

JavaScript

I’ve tried async and await as well as passing one of the functions as a callback. Nothing succeeded:( I think function works bad because of asynchrony. I just started learning of JS, so i am beginner and kindly ask for help! Thanks!

Advertisement

Answer

Because axios already have a callback function, so you only need to call createShortcutsTable(shortcuts ,['name','url']) after iterate and call function axiosGetJSON('json/shortcuts.json'); alone

JavaScript

If you want to use async/await (I don’t recommend it because don’t need to). You have to turn axiosGetJSON function into an async function, which will return a promise to handle by .then(function)

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement