structInsert

Inserts a key-value pair into a structure.

structInsert(structure, key, value [, allowoverwrite]) → returns boolean

Argument Reference

structure struct
Required

Structure to contain the new key-value pair.

key string
Required

Key that contains the inserted value.

value any
Required

Value to add.

allowoverwrite boolean
Default: false

Whether to allow overwriting a key. Default: False.
Values:
  • true
  • false

Examples
Sample code invoking the structInsert function

Inserts a new key/value into the structure

map = {
    "hair" : "brown",
    "eyes" : "green"
};
structInsert(map, "lips", "red");
writeOutput(structKeyList(map));

Expected Result: eyes,lips,hair

Throws exception when you try to add a duplicate key, when allowoverwrite parameter is false.

map = {
    "hair" : "brown",
    "eyes" : "green"
};
try {structInsert(map, "hair", "red", false);}
catch(any ex) {writeOutput("error!");}

Expected Result: error!

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

Fork me on GitHub