# no-sparse-arrays

> Disallow array literals with holes

Two commas in a row leave a hole in the array. `["red",, "blue"]` has a length of 3 and nothing at index 1. `forEach`, `map` and `filter` skip the hole, so the array behaves differently from one that holds `undefined` there. Most of the time the extra comma is a typo.

A trailing comma doesn't make a hole, so it isn't reported. Skipping an element in destructuring isn't reported either.

This rule is on by default.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-sparse-arrays" = "off" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
const colors = ["red",, "blue"];
```

Not reported:

{/* good */}
```js
const colors = ["red", "blue"];
const sizes = ["small", undefined, "large"];
const shapes = [
  "circle",
  "square",
];
const [, second] = colors;
```
