Convert 'new Array(…)' to '[…]'pro
Replace new Array(…)
calls with […]
.
![Convert 'new Array(…)' to '[…]'](/image/documentation/code-assist/convert-new-array-to-array-literal/vscode-example.gif)
What do I need to consider?
Single numeric parameter is a special case in the Array constructor
The new Array()
constructor treats a single number argument in a special way. It indicates the size of an otherwise empty array.
new Array(3); // [,,] (empty x3)
new Array("3"); // ["3"]
new Array(3, 2); // [3, 2]
Configuration
- Code Assist ID (for the configuration file):
convert-new-array-to-array-literal
- You can configure custom keyboard shortcuts with these code action kinds:
refactor.convert.new-array-to-array-literal.p42