# array/slice

``````

cfunction

(array/slice arrtup &opt start end)

Takes a slice of array or tuple from start to end. The range is half
open, [start, end). Indexes can also be negative, indicating indexing
from the end of the end of the array. By default, start is 0 and end
is the length of the array. Note that index -1 is synonymous with
index (length arrtup) to allow a full negative slice range. Returns a
new array.

``````
``````(def a @[1 2 3])
(def b (array/slice a))

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

#=> @[1 2 3]
# good way to convert tuple to array``````
pepe
``````(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
``````
cellularmitosis