JanetDocsPlaygroundI'm feeling luckyGitHub sign in

array/insert



    cfunction
    src/core/array.c on line 263, column 1

    (array/insert arr at & xs)

    Insert all `xs` into array `arr` at index `at`. `at` should be an 
    integer between 0 and the length of the array. A negative value for 
    `at` will index backwards from the end of the array, such that 
    inserting at -1 appends to the array. Returns the array.


3 examplesSign in to add an example
Loading...
(def a @[])
(array/insert a  1 :a)  # error: index out of range
(array/insert a -2 :a)  # error: index out of range
cellularmitosisPlayground
(def a @[1 6])                     # => @[1 6]
(array/insert a 1 (splice [2 3]))  # => @[1 2 3 6]
(array/insert a 3 ;[4 5])          # => @[1 2 3 4 5 6]
cellularmitosisPlayground
(def a @[11 12])              # => @[11 12]
(array/insert a 0 10)         # => @[10 11 12]
(array/insert a 3 13)         # => @[10 11 12 13]
(array/insert a -1 14)        # => @[10 11 12 13 14]
(array/insert a -1 15 16 17)  # => @[10 11 12 13 14 15 16 17]
cellularmitosisPlayground