({{, (RefLink[AssociateTo, paclet:ref/AssociateTo])[a,key->val] 
changes the association a by adding the key-value pair key->val.}, {, (RefLink[AssociateTo, paclet:ref/AssociateTo])[a,{(Subscript[key, 1])->(Subscript[val, 1]),(Subscript[key, 2])->(Subscript[val, 2]),…}]
adds all key-value pairs (Subscript[key, i])->(Subscript[val, i]).}})

OpenersNotesSection(Spacer1)Details

(RefLink[AssociateTo, paclet:ref/AssociateTo]) has attribute (RefLink[HoldFirst, paclet:ref/HoldFirst]).

(RefLink[AssociateTo, paclet:ref/AssociateTo]) effectively modifies the value of a in place.

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Create an association:

assoc = Association[{a->1,b->2,c->3}]

Change the value associated with a:

AssociateTo[assoc, a->11]

If a key is not already in the association, it is added to it:

AssociateTo[assoc, d->4]

Change several values in an association:

assoc = Association[{a->1,b->2,c->3}]

AssociateTo[assoc, {b->22, c->33,d->44}]

Append one association to another:

assoc = Association[{a->1,b->2}]

assoc2 = Association[{c->3}]

AssociateTo[assoc, assoc2]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Association, paclet:ref/Association])  ▪  (RefLink[KeyDropFrom, paclet:ref/KeyDropFrom])  ▪  (RefLink[AppendTo, paclet:ref/AppendTo])  ▪  (RefLink[PrependTo, paclet:ref/PrependTo])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Associations, paclet:guide/Associations])}, {▪(RefLinkPlain[Structured Data in the Cloud, paclet:guide/StructuredDataInTheCloud])}})}})