array

function/macrosince v0.0-927Edit
(array var-args)

(array 1 2 3 ...)

Creates a JavaScript array containing the given args.


Details:

The tagged literal #js [1 2 3] is equivalent to (array 1 2 3)


Examples:

(array 1 2 3)
;;=> #js [1 2 3]

(apply array [1 2 3])
;;=> #js [1 2 3]

#js [1 2 3]
;;=> #js [1 2 3]

When creating nested JavaScript arrays, you can opt to use clj->js instead:

(array 1 2 (array 3 4))
;;=> #js [1 2 #js [3 4]]

(clj->js [1 2 [3 4]])
;;=> #js [1 2 #js [3 4]]

See Also:


Source docstring:
Creates a new javascript array.
@param {...*} var_args
Function code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn ^array array
  [var-args]            ;; [& items]
  (let [a (js/Array. (alength (cljs.core/js-arguments)))]
    (loop [i 0]
      (if (< i (alength a))
        (do
          (aset a i (aget (cljs.core/js-arguments) i))
          (recur (inc i)))
        a))))

Macro code @ clojurescript:src/main/clojure/cljs/core.cljc
(core/defmacro array [& rest]
  (core/let [xs-str (core/->> (repeat "~{}")
                      (take (count rest))
                      (interpose ",")
                      (apply core/str))]
    (vary-meta
      (list* 'js* (core/str "[" xs-str "]") rest)
      assoc :tag 'array)))