Array.insert
Array.insert
Function
Inserts one or more elements at the specified index.
Syntax
array.insert(index, value1, value2, ...)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| index | Int | No | 0 | Insertion position; negative numbers are counted backward from the tail, and if they exceed the boundary, they will be caught at the array boundary. |
| valueN | Any | No | None | The element to insert. |
Return value
| Type | Description |
|---|---|
| Array | Returns the original array object to facilitate continued chain calls. |
Example
items = [1, 4] items.insert(1, 2, 3) // Output: [1,2,3,4] echo(items)
Notes
- insert will modify the original array.
- When you only need to insert elements, insert is more intuitive than splice(index, 0, value).