function | since v0.0-927 | clojure.core/aclone | Edit |
(aclone arr)
Creates a clone of the given JavaScript array arr
. The result is a new
JavaScript array, which is a shallow copy, not a deep copy.
(def a #js [1 2 3])
(def b (aclone a))
(aset b 0 4)
a
;;=> #js [1 2 3]
b
;;=> #js [4 2 3]
Returns a javascript array, cloned from the passed in array
(defn aclone
[arr]
(let [len (alength arr)
new-arr (make-array len)]
(dotimes [i len]
(aset new-arr i (aget arr i)))
new-arr))