# no-array-delete

Rule `sonarjs/no-array-delete`. "delete" should not be used on arrays

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1241 by reach, #542 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-array-delete` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-2870/) |

## Code examples

### Incorrect: the rule reports this

```js
var myArray = ['a', 'b', 'c', 'd'];

delete myArray[2];  // Noncompliant. myArray => ['a', 'b', undefined, 'd']
console.log(myArray[2]); // expected value was 'd' but output is undefined
```

### Correct: the rule accepts this

```js
var myArray = ['a', 'b', 'c', 'd'];

// removes 1 element from index 2
removed = myArray.splice(2, 1);  // myArray => ['a', 'b', 'd']
console.log(myArray[2]); // outputs 'd'
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-array-delete": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [typescript/no-array-delete](https://lintradar.dev/rules/typescript/no-array-delete.md): Disallow using the `delete` operator on array values
- [sonarjs/no-angular-bypass-sanitization](https://lintradar.dev/rules/sonarjs/no-angular-bypass-sanitization.md): Angular built-in sanitization should not be disabled
- [sonarjs/no-associative-arrays](https://lintradar.dev/rules/sonarjs/no-associative-arrays.md): Array indexes should be numeric
- [sonarjs/no-alphabetical-sort](https://lintradar.dev/rules/sonarjs/no-alphabetical-sort.md): "Array.prototype.sort()" and "Array.prototype.toSorted()" should use a compare function
- [sonarjs/no-async-constructor](https://lintradar.dev/rules/sonarjs/no-async-constructor.md): Constructors should not contain asynchronous operations
- [sonarjs/no-all-duplicated-branches](https://lintradar.dev/rules/sonarjs/no-all-duplicated-branches.md): All branches in a conditional structure should not have exactly the same implementation

---

Web page: https://lintradar.dev/rules/sonarjs/no-array-delete. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
