The all() method of the Promise object takes an iterable object as an argument and returns a Promise that fulfills when all of the promises in the iterable object have been fulfilled.
This can be useful when we want to execute a task after some asynchronous operations have finished. Here is a code example that demonstrates how to use the Promise.all() method:
const p1 = new Promise(function(resolve, reject){ setTimeout(function(){ resolve(); }, 1000);});const p2 = new Promise(function(resolve, reject){ setTimeout(function(){ resolve(); }, 2000);});const arr = [p1, p2];Promise.all(arr).then(function(){console.log("Done"); //"Done" is logged after 2 seconds});
If the iterable object contains a value that is ...