5.2.1 Use trailing commas
Example:
5.2.2 Do not use the variadic Array constructor
The constructor is error-prone if arguments are added or removed. Use a literalinstead.
Disallowed:
const a2 = new Array(x1, x2);
const a4 = new Array();
Instead, write
Explicitly allocating an array of a given length using new Array(length)
isallowed when appropriate.
5.2.3 Non-numeric properties
Do not define or use non-numeric properties on an array (other thanlength
). Use a Map
(or Object
) instead.
5.2.4 Destructuring
let [, b,, d] = someArray;
Destructuring may also be used for function parameters (note that a parametername is required but ignored). Always specify []
as the default value if adestructured array parameter is optional, and provide default values on the lefthand side:
Disallowed:
Tip: For (un)packing multiple values into a function’s parameter or return,prefer object destructuring to array destructuring when possible, as it allowsnaming the individual elements and specifying a different type for each.
5.2.5 Spread operator
Example: