Skip to content
Discussion options

You must be logged in to vote

Yes — this behaviour is expected.

  • Array.map() does not “await” anything. It just runs the callback for each element and returns a new array immediately.
  • If your callback is async, it will always return a Promise. So the result of map(async …) is an array of Promises, not the resolved values.

That’s why your log shows:

[ Promise { <pending> }, Promise { <pending> }, Promise { <pending> } ] 

🔑 Key Points:

  1. async function always returns a Promise. Even if you return "hello"; in an async function, it’s really returning Promise.resolve("hello")
  2. map() doesn’t know about async . map() is synchronous — it doesn’t wait for Promises.
  3. Solution → Promise.all()
    If you want the final values, you need…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by CODEhunt89
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Search and Navigation Search, navigate, and understand code on GitHub Question Ask and answer questions about GitHub features and usage
4 participants