Posted about 5 years
Promise.all()
function with that promise array as the input parameter.
then it will dispatch all the promises at once and after all the promises are fulfilled it will resolve an array of objects with the fulfilled individual promises.
gist:RizkyRajitha/721ce1f1e8f6ed0a9f368c3de821a3da
keep in mind that this is all of it or none at all.
So even if one of the child promises got rejected, we will get the whole thing (parent promise) rejected.
array.forEach()
right. But the thing is you cannot use break
statements inside array.forEach()
so, let's say after meeting a specific condition your forEach
loop needs to stop. But you can't do it in forEach
loop. That's where our friend for (let item of array)
comes. This does exactly what array.forEach()
do, but we get the option to break
the forloop
anytime we want in any breakpoint.
Of course, you can use a regular for loop for this. But this is a pretty clean way to get the job donegist:RizkyRajitha/ef461d86fc6116f066fa694d2af5bf08