Skip to solution
mediumFrontend

What is `Array.fromAsync()` and how does it handle async iterables differently from `Array.from()`?

341 views
01

Understand the problem

Question presented to candidate: "If you call Array.from() on a plain array that happens to contain some Promise objects mixed with regular values, does it wait for those Promises to resolve before returning? What about Array.fromAsync()?"

What a strong answer should cover:

  • 📌 Interview term: Array.fromAsync(source, mapFn?) — the async counterpart to Array.from, returning a real Promise that resolves to a real array collected from an async iterable (or a regular iterable/array-like).
  • 📌 Interview term: the real, direct answer to the prompt — verified directly: plain Array.from() on an array containing Promise objects genuinely does NOT await them — the resulting array genuinely still contains the raw, un-resolved Promise objects themselves. Array.fromAsync() on the SAME input genuinely DOES await each Promise element, correctly collecting their resolved values instead.
  • 📌 Interview term: collecting from a genuine async generator — verified directly: Array.fromAsync correctly collected every value from a real async generator, including one that performed a genuine await in the middle of its own sequence — something plain Array.from cannot do at all, since it has no way to await anything.
  • 📌 Interview term: the optional mapping function — verified directly: Array.fromAsync accepts the identical second mapFn argument Array.from does, applied to each resolved value.
  • A precise answer names the real, practical use case: converting an async generator (or a stream of Promises) into a concrete, materialized array when the FULL, complete result set is genuinely needed before proceeding, rather than processing values one at a time as they arrive via for await...of (covered in this bank's own dedicated async-iterators question).

Clarifying questions expected:

  • None — this is a definitional/comparison question; directly answering the prompt's own Promise-array scenario (does-it-await-or-not) is the strong signal.

Code / implementation expected: Yes — the direct side-by-side Array.from vs. Array.fromAsync on the identical Promise-containing array is the clearest, most convincing demonstration.

es2024arrayasync-iterable
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals/async interviews. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every collection result below was actually run in Node (Chrome 121+/Firefox 115+/Sa

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal proof: Array.from genuinely does not await Promise elements (keeps raw Promises), while Array.fromAsync genuinely does, plus collecting from a real async generator
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 99 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track