In the beginning, I was using forEach like this:
products.forEach(async (product) => {
if (
product.type === 'shows' &&
product.isSoldOut &&
product.otherData
) {
delete product.brand.brandId
product.brand.isTop = true
const res = await api.create(product.brand)
console.log(res)
}
})
But issue was that it was getting called after the other calls while should be called before them. After checking some answers in here I switched into for of loop for forcing it to call before the other async operations located after it. But the issue is that it's not getting called at all now. Here is the code:
for (const product of products) {
async () => {
if (
product.type === 'shows' &&
product.isSoldOut &&
product.otherData
) {
delete product.brand.brandId
product.brand.isTop = true
const res = await api.create(product.brand)
console.log(res)
}
}
}
What is wrong? It doesn't get called at all, and how can I force this async calls locaded in the loop get called before the calls located after it?