Skip to content

arrayDeleteUnnecessaryCounts

Reports using .length or Infinity as the deleteCount or skipCount argument of Array#splice() or Array#toSpliced().

✅ This rule is included in the ts stylistic and stylisticStrict presets.

When calling Array#splice(start, deleteCount) or Array#toSpliced(start, skipCount), omitting the second argument will delete or skip all elements after the start index. Using .length or Infinity as this argument is redundant and makes the code less clear.

This rule reports when:

  • The array’s .length property is passed as the second argument
  • Infinity or Number.POSITIVE_INFINITY is passed as the second argument
declare const
const array: number[]
array
: number[];
const array: number[]
array
.
Array<number>.splice(start: number, deleteCount?: number): number[] (+1 overload)

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

@paramstart The zero-based location in the array from which to start removing elements.

@paramdeleteCount The number of elements to remove. Omitting this argument will remove all elements from the start paramater location to end of the array. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements.

@returnsAn array containing the elements that were deleted.

splice
(1,
const array: number[]
array
.
Array<number>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
);
declare const
const array: number[]
array
: number[];
const array: number[]
array
.
Array<number>.splice(start: number, deleteCount?: number): number[] (+1 overload)

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

@paramstart The zero-based location in the array from which to start removing elements.

@paramdeleteCount The number of elements to remove. Omitting this argument will remove all elements from the start paramater location to end of the array. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements.

@returnsAn array containing the elements that were deleted.

splice
(0,
var Infinity: number
Infinity
);
declare const
const array: number[]
array
: number[];
const array: number[]
array
.
Array<number>.splice(start: number, deleteCount?: number): number[] (+1 overload)

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

@paramstart The zero-based location in the array from which to start removing elements.

@paramdeleteCount The number of elements to remove. Omitting this argument will remove all elements from the start paramater location to end of the array. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements.

@returnsAn array containing the elements that were deleted.

splice
(0,
var Number: NumberConstructor

An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

Number
.
NumberConstructor.POSITIVE_INFINITY: number

A value greater than the largest number that can be represented in JavaScript. JavaScript displays POSITIVE_INFINITY values as infinity.

POSITIVE_INFINITY
);
declare const
const array: number[]
array
: number[];
const array: number[]
array
.toSpliced(1,
const array: number[]
array
.
Array<number>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
);
Error ts(2550) ― Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.

This rule is not configurable.

If you prefer the explicit style of passing .length or Infinity to make the intent clearer, you can disable this rule. Some teams may find the explicit version more readable, especially for developers less familiar with the splice method’s default behavior.

Made with ❤️‍🔥 around the world by the Flint team and contributors.