Array.slice
Array.slice
Function
Copy the array fragment according to the starting and ending indexes.
Syntax
array.slice(start, end)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| start | Int | No | 0 | Starting subscript; a negative number means counting backwards from the tail. |
| end | Int | No | Array length | End subscript, excluding this position; a negative number means backward calculation from the tail. |
Return value
| Type | Description |
|---|---|
| Array | Returns a new array. |
Example
items = [1, 2, 3, 4] result = items.slice(1, 3) // Output: [2,3] print result
Notes
- The original array will not be modified.