π Prefer Array.from({length}, β¦) when creating range arrays.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§ This rule is automatically fixable by the --fix CLI option.
Prefer Array.from({length}, (_, index) => index) when directly materializing a range from Array(length).keys() or new Array(length).keys().
This rule only reports direct array materialization from Array constructor ranges. Lazy iterator use, values(), entries(), computed members, optional calls, and shadowed Array bindings are ignored.
// β
const indexes = [...Array(length).keys()];
// β
const indexes = Array.from({length}, (_, index) => index);// β
const indexes = Array.from(Array(count + 1).keys());
// β
const indexes = Array.from({length: count + 1}, (_, index) => index);// β
for (const index of Array(length).keys()) {
console.log(index);
}