> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-sparse-arrays

[Added in v0.1.14](https://github.com/web-infra-dev/rslint/releases/tag/v0.1.14)
## Configuration

| Preset                   | Configured Value |
| ------------------------ | ---------------- |
| ✅ js.configs.recommended | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-sparse-arrays': 'error',
    },
  },
]);
```

## Rule Details

Disallows sparse arrays, which are array literals that contain empty slots created by extra commas. Sparse arrays can be confusing because the empty slots are `undefined` but behave differently from explicitly setting an element to `undefined` (for example, `Array.prototype.forEach` skips sparse entries). Extra commas are usually a typo.

Examples of **incorrect** code for this rule:

```javascript
var items = [1, , 3];

var colors = ['red', , 'blue'];
```

Examples of **correct** code for this rule:

```javascript
var items = [1, 2, 3];

var colors = ['red', 'blue'];

var arr = [1, undefined, 3]; // explicit undefined is fine
```

## Original Documentation

- [ESLint: no-sparse-arrays](https://eslint.org/docs/latest/rules/no-sparse-arrays)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/no-sparse-arrays.js)
