Skip to content

eslint/no-sparse-arrays Correctness

This rule is turned on by default.

What it does

Disallow sparse arrays.

Why is this bad?

The confusion around sparse arrays is enough that it’s recommended to avoid using them unless you are certain that they are useful in your code.

Example

javascript
var items = [, ,];
var colors = ["red", , "blue"];

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny no-sparse-arrays
json
{
  "rules": {
    "no-sparse-arrays": "error"
  }
}

References

Released under the MIT License.