INSERT
INSERT a, idx, val [, val [, …]]]
Inserts the values to the specified array at the position idx.
- a - An array-variable.
- idx - Position in the array.
- val - Any value or expression.
Example 1: Insert one variable
1,2,3,4,5]
a = [
print a
insert a, 3, 6
print a
' Output:
' [1,2,3,4,5]
' [1,2,3,6,4,5]
Example 2: Insert several variables
1,2,3,4,5]
a = [
print a
insert a, 3, 6, 7, 8
print a
' Output:
' [1,2,3,4,5]
' [1,2,3,8,7,6,4,5]
Please be aware, that multiple variables will be sequentially inserted each at position 3. This leads to a reverse order.
Example 3: Insert an array
1,2,3,4,5]
a = [
print a
insert a, 3, [6,7]
print a
' Output:
' [1,2,3,4,5]
' [1,2,3,[6,7],4,5]
Example 4: Insert a map variable
1,2,3,4,5]
a = [6, y:7}
b = {x:
print a
insert a, 3, b
print a
' Output:
' [1,2,3,4,5]
' [1,2,3,{"y":7, "x":6},4,5]
Example 5: Append a variable (insert at last position)
1,2,3,4,5]
a = [
print a
6
a << print a
' Output:
' [1,2,3,4,5]
' [1,2,3,4,5,6]
Code samples using INSERT
Data
APPEND
ARRAY
DATA
DELETE
DIM
EMPTY
ERASE
INSERT
ISARRAY
ISDIR
ISFILE
ISLINK
ISMAP
ISNUMBER
ISSTRING
LBOUND
LEN
READ
REDIM
RESTORE
SEARCH
SORT
SWAP
UBOUND
If there is insufficient information on this page and you wish learn more about INSERT,
please send an email to smallbasic@gmail.com. You can help to improve information about
INSERT by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.