I have created a time-consuming function to show how it works with different for loops.
Test using an asynchronous function.
From this example, we can clearly see forEach(), not giving the expected results and not waiting until the finishing of execution of the time-consuming function.
let’s see an example of how to do it
For loop gave the expected answer and waited until the finishing of execution of the time-consuming function.
Don’t hesitate to share any comment with me.