Last updated on
|
Also Applies to ColdFusion
Description
Determines whether a specific key is present in a structure.
Returns
"YES", if key is in structure, otherwise "NO".
Category
Syntax
StructKeyExists(structure, "key")
See also
Structure functions; Structure functions in the Developing ColdFusion Applications
Parameters
Parameter |
Description |
---|---|
structure |
The structure to test. |
key |
Key to test. |
Example
<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>
Output
YES | NO
Using member function
<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