Pattern: Use of new Array()
constructor
Issue: -
The Array
constructor with a single argument is ambiguous - it's unclear whether the argument specifies the array length or is meant to be the only element. Use Array.from()
for length initialization or array literals for single elements.
Example of incorrect code:
const array = new Array(1);
const array = new Array(42);
const array = new Array(foo);
Example of correct code:
const array = Array.from({ length: 42 });
const array = [42];