INSERT
Root / Documentation / [.]

Insert values into a 1D array.
Syntax
INSERT array[], index% {, amount% {, value }}
Input | Description |
---|---|
array[] | The array to insert values into. |
index% | The index to insert values at. |
amount% | The number of values to insert. Optional, default 1. |
value | The value to insert. Optional |
INSERT
resizes array[]
by inserting elements at index%
. Elements after the insertion index are shifted toward the end. By default, one element is inserted and assigned to the default value of the array's type.
Type | Value |
---|---|
Integer | 0 |
Real | 0.0 |
String | "" |
index%
cannot be less than 0 or more than the length of array[]
. If index%
equals the length, the new elements are added at the end.
If amount%
is passed, then multiple new elements are added starting at index%
; e.g. if index%
is 4 and amount%
is 3, then new elements are added at 4, 5, and 6.
If value
is passed, then that value is assigned to all new indices instead of the default. value
and array[]
must have compatible types.
INSERT
cannot be used on multidimensional arrays.
Examples
'insert zero DIM ARRAY[2]=[1,2] INSERT ARRAY,1 INSPECT ARRAY
'insert three zeros DIM ARRAY[2]=[1,2] INSERT ARRAY,1,3 INSPECT ARRAY
'insert three tens DIM ARRAY[2]=[1,2] INSERT ARRAY,1,3,10 INSPECT ARRAY
See Also
No posts yet (will you be the first?)