Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 1.43 KB

no-array-constructor.md

File metadata and controls

62 lines (43 loc) · 1.43 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);

How to use

To enable this rule in the CLI or using the config file, you can use:

::: code-group

oxlint --deny no-array-constructor
{
  "rules": {
    "no-array-constructor": "error"
  }
}

:::

References