persona-community-5/.pnpm-store/v3/files/19/17b96fba4b028c13c3d123df88e8a93d6aeee374db3591ad1dae059c4b296761b2201a7c9c3e387b29bc28f9ce8240f10e6a0c12e1636d3e8bc1d280b99f2f
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

45 lines
1.2 KiB
Plaintext

---
description: 'Disallow using the `delete` operator on array values.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-array-delete** for documentation.
When using the `delete` operator with an array value, the array's `length` property is not affected,
but the element at the specified index is removed and leaves an empty slot in the array.
This is likely to lead to unexpected behavior. As mentioned in the
[MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#deleting_array_elements),
the recommended way to remove an element from an array is by using the
[`Array#splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) method.
## Examples
<Tabs>
<TabItem value="❌ Incorrect">
```ts
declare const arr: number[];
delete arr[0];
```
</TabItem>
<TabItem value="✅ Correct">
```ts
declare const arr: number[];
arr.splice(0, 1);
```
</TabItem>
</Tabs>
## When Not To Use It
When you want to allow the delete operator with array expressions.