Adding values to a Vector

The conj function will add a value to an existing vector.

(conj [1 2 3] 4)
(conj ["Can" "we" "join"] ["two" "collections"])
(conj ["Can" "we" "join"] "multiple" "values")
(conj ["Mint" "Vanilla"] "Chocolate")

A vector is immutable. Once you create a vector, it is not possible to change it.

conj like most Clojure functions returns a new vector with the value from the original vector and the new value.

Add values to a vector

Use the conj function to return a new vector with the added value

()

Hint

A common way to remove values from a vector is to use either the filter or remove functions.

results matching ""

    No results matching ""