---
title: "unicorn/no-unnecessary-array-splice-count"
description: "Disallow `.length` or `Infinity` as the count of `splice()` and `toSpliced()`"
# Generated by src/codegen/lint-rule-docs.ts. Do not edit below this line.
plugin: "unicorn"
aliases: []
kind: "suggestion"
category: "pedantic"
default: "off"
fixable: "yes"
typeAware: false
deprecated: false
---

`splice(start)` and `toSpliced(start)` already remove everything from `start` to the end of the array. Passing the array's `.length`, `Infinity` or `Number.POSITIVE_INFINITY` as the second argument does the same thing with more code.

`--fix` removes the second argument.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/no-unnecessary-array-splice-count" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```js
queue.splice(3, queue.length);
queue.splice(3, Infinity);

const firstThree = queue.toSpliced(3, Number.POSITIVE_INFINITY);
```

Not reported:

{/* good */}
```js
queue.splice(3);

const firstThree = queue.toSpliced(3);

// a real count, the length of another array, or items to insert
queue.splice(3, 2);
queue.splice(3, removed.length);
queue.splice(3, queue.length, next);
```
