Skip to content

no-sparse-arrays

Reports a hole in an array literal, at the extra comma: [1, , 2] and [, 1]. A single trailing comma ([1, ]) is not a hole.

A hole is an index with no element. [1, , 2] has the length 3, and methods such as forEach and map skip the hole while for loops and spread read it as undefined, so the same array behaves differently depending on how it is read. It is nearly always a typo for a single comma.

To fix, remove the extra comma, or write undefined (or null) where a value is meant.

Reported
...
class K { static {} }
...
var x = [1, , 2, ,], y = [[], [,]];
...
js:
lint:
rules:
no-sparse-arrays: warn # off, warn (default), error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-sparse-arrays in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-sparse-arrays full