I've solved this problem before by using Array#reduce to basically build a big Promise chain.
Array#reduce
It's something like
await posts.data.reduce((prev, curr) => prev.then(async post => { let user = await axios(`${baseURL}/users/${post.userId}`); console.log(user.data.name); }), Promise.resolve())
If I only need the result to ordered and don't care about the actual execution order, I use Array#map with Promise#all
Array#map
Promise#all
const result = Promise.all(posts.data.map(async post => await axios(`${baseURL}/users/${post.userId}`)))
(in this example both the async and await can be left out since only the plain promises get used, but it should get the thought across)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I've solved this problem before by using
Array#reduce
to basically build a big Promise chain.It's something like
If I only need the result to ordered and don't care about the actual execution order, I use
Array#map
withPromise#all
(in this example both the async and await can be left out since only the plain promises get used, but it should get the thought across)