Description

Updates a key with a value.

Returns

Returns the updated struct; if the structure does not exist, ColdFusion throws an error.

Category

Syntax

StructUpdate(structure, key, value)

See also

Structure functionsModifying a ColdFusion XML object in the Developing ColdFusion Applications

History

ColdFusion (2018 release): Returns the updated struct.

ColdFusion MX: Changed behavior: this function can be used on XML objects.

Parameters

Parameter

Description

structure

Structure to update.

key

Key, the value of which to update.

value

New value.

Example

<cfscript>
       myStruct=StructNew();
       myStruct={a=1,b=2,c=3,d=4,e=5};
       WriteOutput("Before struct update:");
       WriteDump(myStruct);
       StructUpdate(myStruct,"e",6); // Update key-value pair e-5 to e-6
       WriteOutput("After struct update:");
       WriteDump(myStruct);
</cfscript>

Output

structupdate output
structupdate output

Using member function

<cfscript>
       myStruct={a=1,b=2,c=3,d=4,e=5};
       myStruct.update("e",6);
       WriteDump(myStruct);
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy