I am trying to make an async
request within foreach
to fetch data in order user it later but its not working for me.
I know Array.Foreach
is a synchronous function so I even tried $.when.done but still it does not wait until it finish.
I could have used callback if it was a single value but its an array .
Is there a better way to handle this by callback to achieve waiting on async
request before moving next?
browseItems.forEach((browseItem: any) => {
AsynchFunction();
cosole.log("Step 2")
}
function AsynchFunction(){
console.log("Step 1")
}
I am trying to get an output like
Step 1
Step 2