CCNA
CCNA

Reputation: 387

How can I update a map using the `update` function?

   (def p {:name "James" :age 26})

I'm trying update method, like

(update p :name "David") 

which does not work since the second argument has to be a function.

Upvotes: 1

Views: 134

Answers (1)

Alan Thompson
Alan Thompson

Reputation: 29958

Try this:

(assoc p :name "David")

Please see this list of documentation, especially the Clojure CheatSheet! See also assoc-in and update-in as described under

Collections -> Maps

P.S. What you have there is a Clojure map value, which is different than an object in JavaScript or a JSON string.

Upvotes: 3

Related Questions