Skip to main content

no-array-delete

Disallow using the delete operator on array values.

💡

Some problems reported by this rule are manually fixable by editor suggestions.

💭

This rule requires type information to run.

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, the recommended way to remove an element from an array is by using the Array#splice method.

.eslintrc.cjs
module.exports = {
"rules": {
"@typescript-eslint/no-array-delete": "error"
}
};

Try this rule in the playground ↗

Examples

declare const arr: number[];

delete arr[0];
Open in Playground

Options

This rule is not configurable.

When Not To Use It

When you want to allow the delete operator with array expressions.


Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.

See Troubleshooting > Linting with Type Information > Performance if you experience performance degredations after enabling type checked rules.

Resources