structAppend

Appends one structure to another.

structAppend(destStruct, sourceStruct [, overwriteFlag]) → returns boolean

Member Function Syntax

destStruct.append(sourceStruct [, overwriteFlag]) → returns struct

Argument Reference

destStruct struct
Required

Structure to append.

sourceStruct struct
Required

Structure that contains the data to append to destStruct

overwriteFlag boolean
Default: true

Whether values in sourceStruct should overwrite corresponding values in
destStruct or not.
Values:
  • true
  • false

Compatibility

ColdFusion:

CF6+ can be used on XML objects as well as structures.

Links more information about structAppend

Examples
Sample code invoking the structAppend function

config = {a:0, b:0};
options= {b:1, c:1};
structAppend(config, options, false);
writeOutput( serializeJSON( config ) );

Expected Result: {"A":0,"B":0,"C":1}

config = {a:0, b:0};
options= {b:1, c:1};
config.append(options, false);
writeOutput( serializeJSON( config ) );

Expected Result: {"A":0,"B":0,"C":1}

config = {a:0, b:0};
options= {b:1, c:1};
structAppend(config, options);
writeOutput( serializeJSON( config ) );

Expected Result: {"A":0,"B":1,"C":1}

Demonstrates how to construct a Request Context (rc) that combines the values of the form and url scopes

rc = {};
structAppend( rc, form );
structAppend( rc, url );
writeOutput( serializeJSON( rc ) );

In older ColdFusion version where this function is not supported yet, you can fall back to a native java method to achieve the same behavior except that it does not have the overwriteFlag.

config = {a:0, b:0};
options= {b:1, c:1};
config.putAll(options);
writeOutput( serializeJSON( config ) );

Expected Result: {"A":0,"B":0,"C":1}

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub