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
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
@param ― start The zero-based location in the array from which to start removing elements.
@param ― deleteCount 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.
@returns ― An 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.
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
@param ― start The zero-based location in the array from which to start removing elements.
@param ― deleteCount 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.
@returns ― An array containing the elements that were deleted.
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
@param ― start The zero-based location in the array from which to start removing elements.
@param ― deleteCount 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.
@returns ― An 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.
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
@param ― start The zero-based location in the array from which to start removing elements.
@param ― deleteCount 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.
@returns ― An array containing the elements that were deleted.
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
@param ― start The zero-based location in the array from which to start removing elements.
@param ― deleteCount 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.
@returns ― An array containing the elements that were deleted.
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
@param ― start The zero-based location in the array from which to start removing elements.
@param ― deleteCount 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.
@returns ― An 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.
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
@param ― start The zero-based location in the array from which to start removing elements.
@param ― deleteCount 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.
@returns ― An array containing the elements that were deleted.
splice(1,
const other:number[]
other.
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.
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.