disallow Array constructors (no-array-constructor)

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.

Rule Details

This rule disallows Array constructors.

Examples of incorrect code for this rule:

/*eslint no-array-constructor: "error"*/

Array(0, 1, 2)

new Array(0, 1, 2)

Examples of correct code for this rule:

/*eslint no-array-constructor: "error"*/

Array(500)

new Array(someOtherArray.length)

[0, 1, 2]

When Not To Use It

This rule enforces a nearly universal stylistic concern. That being said, this rule may be disabled if the constructor style is preferred.

Version

This rule was introduced in ESLint 0.4.0.

Resources

Js中文网,专注分享前端最新技术、大厂面试题、聊点程序员轶事、职场感悟,做前端技术的传播者.

加入前端布道师交流群

扫描二维码回复 加群 学习,与大厂大佬讨论技术.

BAT面试题大全