π Prefer Iterator#toArray() over temporary arrays from iterator spreads.
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
π§π‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor 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.
// β
const values = [...map.values()];
// β
const values = map.values().toArray();// β
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().
// β
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.
// β
new Set([...map.values()]);Mixed arrays and multi-spread arrays are intentionally ignored.
// β
const values = [first, ...map.values()];
// β
const values = [...foo, ...bar];