# prefer-iterator-to-array πŸ“ Prefer `Iterator#toArray()` over temporary arrays from iterator spreads. πŸ’ΌπŸš« This rule is enabled in the βœ… `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). This rule is _disabled_ in the β˜‘οΈ `unopinionated` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). Prefer `Iterator#toArray()` over temporary arrays created with a single iterator spread. `Iterator#toArray()` makes iterator-to-array conversion explicit and keeps iterator helper chains readable. ## Examples ```js // ❌ const values = [...map.values()]; // βœ… const values = map.values().toArray(); ``` ```js // ❌ const values = [...map.values().map(value => value * 2)]; // βœ… const values = map.values().map(value => value * 2).toArray(); ``` This rule is intentionally narrow. It does not report arbitrary iterables because not every iterable has `Iterator#toArray()`. ```js // βœ… const values = [...set]; ``` Calls like `.values()`, `.keys()`, `.entries()`, and `.matchAll()` are reported as suggestions because custom methods with those names may return non-iterator iterables. Iterable-accepting contexts are intentionally ignored because they do not need an array. ```js // βœ… new Set([...map.values()]); ``` Mixed arrays and multi-spread arrays are intentionally ignored. ```js // βœ… const values = [first, ...map.values()]; // βœ… const values = [...foo, ...bar]; ```