DEV Community

CodeWellTechYT
CodeWellTechYT

Posted on

Promise.all() in JavaScript

How promise.all method works?

The Promise.allmethod takes an iterable of promises as an input, and returns a single Promise that resolves to an array of the results of the input promises.

Check the video where Promise.all explained with realtime examples and eror handling.

Guess the output ?


const promise1=Promise.resolve("First Promise");
const promise2=new Promise((resolve,reject)=>{
   setTimeout(() => {
     reject("Second Promise");
   }, 1000);
});

const promiseAll=Promise.all([promise1,promise2]);
promiseAll.then((values)=>{
  console.log(values[0]);
  console.log(values[1]);
});


Enter fullscreen mode Exit fullscreen mode

Top comments (0)