Skip to main content
Up or down tonavigateEnter toselectEscape toclose⌘⇧KAI

no-sparse-arrays

Disallows sparse arrays.

Sparse arrays are arrays that contain empty slots, which later could be handled either as undefined value or skipped by array methods, and this may lead to unexpected behavior:

[1, , 2].join(); // => '1,,2'
[1, undefined, 2].join(); // => '1,,2'

[1, , 2].flatMap((item) => item); // => [1, 2]
[1, undefined, 2].flatMap((item) => item); // => [1, undefined, 2]

Invalid:

const items = ["foo", , "bar"];

Valid:

const items = ["foo", "bar"];

Did you find what you needed?

Privacy policy