Skip to content
Advertisement

Promise.all() to await the return of an object property

Inside an async function i have a loop and inside this loop i need to use await to resolve a promise from another async function.

JavaScript

It’s work fine, but eslint says to disallow await inside of loops and use Promise.all() to resolve all promises.

The problem is that my promises are in an object property:

return of the function

How can i figure out to use Promise.all() with properties of an object?

Advertisement

Answer

Chain a .then onto the lengthOfState call to make the whole Promise resolve to the object you need, inside the Promise.all:

JavaScript
Advertisement