Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.17 KB

File metadata and controls

42 lines (29 loc) · 1.17 KB

eslint/no-array-constructor

🚧 An auto-fix is still under development.

What it does

Disallows creating arrays with the Array constructor.

Why is this bad?

Use of the Array constructor to construct a new array is generally discouraged in favor of array literal notation because of the single-argument pitfall and because the Array global may be redefined. The exception is when the Array constructor is used to intentionally create sparse arrays of a specified size by giving the constructor a single numeric argument.

Examples

Examples of incorrect code for this rule:

let arr = new Array();

Examples of correct code for this rule:

let arr = [];
let arr2 = Array.from(iterable);
let arr3 = new Array(9);

References