JanetDocsI'm feeling luckyGithub sign in

array/insert



    cfunction

    (array/insert arr at & xs)
    
    Insert all of xs into array arr at index at. at should be an integer 0
    and the length of the array. A negative value for at will index 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
cellularmitosis
(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]
cellularmitosis
(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]
cellularmitosis