Keep item lines uniform
Formatting multiline arrays
JS Puzzles · Const
A trailing comma after the last item in an array literal is allowed and ignored. It keeps multiline array edits consistent, but additional commas create sparse-array holes.
A trailing comma may appear after the last item in a JavaScript array literal. It does not create another element, and it can make multiline edits easier because each item line has the same format.
const array = [element1, element2,];const fruits = [
"Apple",
"Orange",
"Plum",
];
console.log(fruits.length); // 3
console.log(fruits[2]); // "Plum"The final comma is ignored, so the array contains three elements.
Formatting multiline arrays
Maintaining source code
Avoiding accidental sparse arrays
Array literalsSparse arraysArray.prototype.forEach()Array.prototype.map()