I have a few async functions that need to work in nested for loops but the await fails if it's not in the first for loop, or in the base level function.
I tried moving my await up and down the levels of the for loop, and found that after the first for loop, it fails.
Any suggestions what I should try?
async function Func2() {
//DO ASYNC STUFF
};
async function Func3() {
//DO ASYNC STUFF
};
async function Func1() {
var Data = await Func2(); //THIS AWAIT WORKS
for (var X1 = 0; X1 <= 10; X1++) {
//AWAIT WOULD WORK HERE
Object.keys(Data[0]).forEach(function (key2) {
//BUT NOT HERE.
Object.keys(rows).forEach(function (key) {
var Data = await Func3(); //THIS AWAIT ERRORS: "await is only valid in async function"
});
})
};
}
Func1();