# prefer-array-from-async

Rule `unicorn/prefer-array-from-async`. Prefer `Array.fromAsync()` over array accumulation loops.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1060 by reach, #1315 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-array-from-async` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-array-from-async.md) |

## Code examples

### Incorrect: the rule reports this

```js
const result = [];
for await (const element of iterable) {
  result.push(element);
}
```

```js
const result = [];
for await (const element of iterable) {
  result.push(await transform(element));
}
```

```js
const paths = ['a.txt', 'b.txt'];
const contents = [];
for (const path of paths) {
  contents.push(await readFile(path));
}
```

### Correct: the rule accepts this

```js
const result = await Array.fromAsync(iterable);
```

```js
const result = await Array.fromAsync(iterable, element => transform(element));
```

```js
const result = [];
for await (const element of iterable) {
  result.push(transform(element));
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-array-from-async": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-abort-signal-timeout](https://lintradar.dev/rules/unicorn/prefer-abort-signal-timeout.md): Prefer `AbortSignal.timeout()` over manually aborting an `AbortController` with `setTimeout()`.
- [unicorn/prefer-array-iterable-methods](https://lintradar.dev/rules/unicorn/prefer-array-iterable-methods.md): Prefer iterating an array directly or with `Array#keys()` over `Array#entries()` when the index or value is unused.
- [unicorn/prefer-abort-signal-any](https://lintradar.dev/rules/unicorn/prefer-abort-signal-any.md): Prefer `AbortSignal.any()` over manually forwarding abort events between signals.
- [unicorn/prefer-array-slice](https://lintradar.dev/rules/unicorn/prefer-array-slice.md): Prefer `Array#slice()` over `Array#splice()` when reading from the returned array.
- [unicorn/operator-assignment](https://lintradar.dev/rules/unicorn/operator-assignment.md): Require assignment operator shorthand where possible.
- [unicorn/prefer-combined-guards](https://lintradar.dev/rules/unicorn/prefer-combined-guards.md): Prefer combining consecutive guards with identical exit statements.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-array-from-async. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
