I have the following code:
console.log("TEST 1");
accounts.forEach(async function(account) {
console.log("TEST 2");
try {
var data = await getReservations(account);
} catch(err) {
res.status(err.error_code).json(err);
}
console.log("TEST 3");
});
console.log("TEST 4");
When it's run, the console reads:
TEST 1
TEST 2
TEST 4
getReservations()
TEST 3
But I want it to wait for getReservations()
to finish before it continues past the forEach()
. I would like it to output:
TEST 1
TEST 2
getReservations()
TEST 3
TEST 4
Any ideas?