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 functionsStructure functions in the Developing ColdFusion Applications

Parameters

Parameter

Description

structure

Name of 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

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy