Array.splice
Array.splice
Function
Removes the specified range from the array and inserts new elements.
Syntax
array.splice(start, delete_count, value1, value2, ...)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| start | Int | No | 0 | The index to start deletion; a negative number means counting backwards from the tail. |
| delete_count | Int | No | from start to end | Number of elements to delete; negative numbers are treated as 0. |
| valueN | Any | No | None | The new element to insert. |
Return value
| Type | Description |
|---|---|
| Array | Returns a new array consisting of deleted elements. |
Example
items = [1, 2, 3, 4] removed = items.splice(1, 2, 8, 9) // Output: [2,3] echo(removed) // Output: [1,8,9,4] echo(items)
Notes
- This method will modify the original array.