How to wait for multiple promises in javascript

Suppose you want fire up 2 or multiple promises requests at the same time and perform some action on completion of all the requested promises.

How do you achieve that ?

Use Promise.all() method :

    const promiseRequest1 = //...
    const promiseRequest2 = //...

    const result = await Promise.all([promiseRequest1, promiseRequest2])

    const dataFromPromiseRequest1 = result[0]
    const dataFromPromiseRequest2 = result[1]

The above sytax is with using async and wait, but if you prefer to use pure promise without async and await.

You could use below syntax

    const promiseRequest1 = //...
    const promiseRequest2 = //...

    Promise.all([promiseRequest1, promiseRequest2]).then(result => {
        const dataFromPromiseRequest1 = result[0]
        const dataFromPromiseRequest2 = result[1]
    }