User Guide Cancel

StructDelete

 

Description

Removes an element from a structure.

Returns

Returns true, if an element is deleted successfully. False, otherwise.

Category

Syntax

StructDelete(structure, key [, indicatenotexisting ])
StructDelete(structure, key [, indicatenotexisting ])
StructDelete(structure, key [, indicatenotexisting ])

See also

Structure functionsModifying a ColdFusion XML object in the Developing ColdFusion Applications

History

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

Parameters

Parameter

Description

structure

Structure or a variable that contains one. Contains element to remove.

key

Element to remove.

indicatenotexisting

  • True: returns Yes if key exists; No if it does not.
  • False: returns Yes regardless of whether key exists. Default.

Example

<cfscript>
myStruct={a:1,b:2,c:3,d:4,e:5};
WriteOutput("The input struct is:");
WriteDump(myStruct);
xFalse=StructDelete(myStruct,"f",false);// Returns Yes regardless of whether key exists
WriteOutput(xFalse & " | "); //Display Yes
xTrue=StructDelete(myStruct,"f","true");// Returns No since the key "f" does not exist in the input struct
WriteOutput(xTrue & " | "); //Display No
// Delete an element that actually exists in the input structure
StructDelete(myStruct,"e",true); // Deletes element "e" from the struct and returns Yes
WriteOutput("The updated struct is:");
WriteDump(myStruct);
</cfscript>
<cfscript> myStruct={a:1,b:2,c:3,d:4,e:5}; WriteOutput("The input struct is:"); WriteDump(myStruct); xFalse=StructDelete(myStruct,"f",false);// Returns Yes regardless of whether key exists WriteOutput(xFalse & " | "); //Display Yes xTrue=StructDelete(myStruct,"f","true");// Returns No since the key "f" does not exist in the input struct WriteOutput(xTrue & " | "); //Display No // Delete an element that actually exists in the input structure StructDelete(myStruct,"e",true); // Deletes element "e" from the struct and returns Yes WriteOutput("The updated struct is:"); WriteDump(myStruct); </cfscript>
<cfscript>
       myStruct={a:1,b:2,c:3,d:4,e:5};
       WriteOutput("The input struct is:");
       WriteDump(myStruct);
       xFalse=StructDelete(myStruct,"f",false);// Returns Yes regardless of whether key exists
       WriteOutput(xFalse & " | "); //Display Yes
       xTrue=StructDelete(myStruct,"f","true");// Returns No since the key "f" does not exist in the input struct
       WriteOutput(xTrue & " | "); //Display No
       // Delete an element that actually exists in the input structure
       StructDelete(myStruct,"e",true); // Deletes element "e" from the struct and returns Yes
       WriteOutput("The updated struct is:");
       WriteDump(myStruct);
</cfscript>

Output

structdelete output
structdelete output

Using member function

<cfscript>
myStruct={a:1,b:2,c:3,d:4,e:5};
WriteOutput(myStruct.delete("c",true));
</cfscript>
<cfscript> myStruct={a:1,b:2,c:3,d:4,e:5}; WriteOutput(myStruct.delete("c",true)); </cfscript>
<cfscript>
       myStruct={a:1,b:2,c:3,d:4,e:5};
       WriteOutput(myStruct.delete("c",true));
</cfscript>

Get help faster and easier

New user?