Determines whether a specific key is present in a structure.
"YES", if key is in structure, otherwise "NO".
StructKeyExists(structure, "key")
Structure functions; Structure functions in the Developing ColdFusion Applications
Parameter |
Description |
|---|---|
structure |
Name of structure to test. |
key |
Key to test. |
<cfscript>
myStruct=StructNew();
myStruct = {a:1,b=2,c=3,d=4,e=5};
ifKeyExists=StructKeyExists(myStruct,"c"); //Returns Yes since key "c" exists
WriteOutput(ifKeyExists & "|");
ifKeyNotExist=StructKeyExists(myStruct,"f"); //Returns No since key "f" does not exist
WriteOutput(ifKeyNotExist);
</cfscript>
YES | NO
<cfscript>
myStruct = {a:1,b=2,c=3,d=4,e=5};
myKeyExists=myStruct.keyExists("e");
WriteOutput(myKeyExists);
</cfscript>
Output
Does the struct key exist: YES
Sign in to your account