JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

array/slice

core-api


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

    (array/slice ind &opt start end)

    Same as `tuple/slice`, but returns an array.


3 examplesSign in to add an example
Loading...
(def a @[1 2 3])
(def b (array/slice a))

#=> good way to clone array, a and b are different arrays
pepePlayground
(array/slice [1 2 3])

#=> @[1 2 3]
# good way to convert tuple to array
pepePlayground
(array/slice @[1 2 3] 0 0)  # => @[]
(array/slice @[1 2 3] 0 1)  # => @[1]
(array/slice @[1 2 3] 0 2)  # => @[1 2]
(array/slice @[1 2 3] 0 3)  # => @[1 2 3]
(array/slice @[1 2 3] 0 4)  # error: index out of range

(array/slice @[1 2 3] 1 1)  # => @[]
(array/slice @[1 2 3] 1 2)  # => @[2]

(array/slice @[1 2 3] 0 -1)  # => @[1 2 3]
(array/slice @[1 2 3] 0 -2)  # => @[1 2]
(array/slice @[1 2 3] 0 -3)  # => @[1]
(array/slice @[1 2 3] 0 -4)  # => @[]
(array/slice @[1 2 3] 0 -5)  # error: index out of range
cellularmitosisPlayground