JS Built-ins
← Array17 / 226
ArrayArray.fromAsyncadvanced

Array.fromAsync() β€” resolve an array of promises

πŸ“– Usage Example
// Real usage (async context):
const promises = [Promise.resolve(1), Promise.resolve(2)]
const result = await Array.fromAsync(promises)
// β†’ [1, 2]

Use Array.fromAsync() to resolve an iterable of promises into a plain array.

Array.fromAsync()

Array.fromAsync() is the async counterpart of Array.from(). It accepts an async iterable, a sync iterable, or an array-like object of promises and resolves them all into a plain array.

The synchronous equivalent is Promise.all(promises).then(Array.from), which this exercise uses so the tests can run synchronously.

Challenge: Implement resolveAll that takes an array of already-resolved numbers and returns them as a plain array (simulating what Array.fromAsync would do).

resolveAll([1, 2, 3]) // β†’ [1, 2, 3]
πŸ’‘ Hints (2)
  • β€’ `Array.fromAsync(arrayOfPromises)` awaits each promise and collects results.
  • β€’ The sync equivalent for already-resolved values is simply `Array.from(values)`.