Description

Determines the value associated with a key in a structure.

Returns

The value associated with a key in a structure; if a structure does not exist, the function throws an exception.

Category

Syntax

StructFind(structure, key)

See also

Structure functionsStructure functions in the Developing ColdFusion Applications

Parameters

Parameter

Description

structure

Structure that contains the value to return.

key

Key whose value to return.

Example

<cfscript>
       myStruct=StructNew();
       myStruct={a:1,b:2,c:3,d:4,e:5}; //Define structure keys
       WriteOutput("The values are: ");
       for (key in myStruct){ //Find keys in the struct
             WriteOutput(StructFind(myStruct,#key#) & " | "); //Display the value if key is found
       }
       // Try to search for the key "f" that does not exist in myStruct
       // Since the key is not in the struct, an error message is displayed
       try{
             StructFind(myStruct,"f");
       }
       catch (any e)
       {
             WriteOutput(e.message);
       }
</cfscript>

Output

The values are: 1 | 2 | 3 | 4 | 5 | 

Cannot find f key in structure.

Using member function

<cfscript>
       myStruct={a:1,b:2,c:3,d:4,e:5}; //Define structure keys
       myFind=myStruct.find("c"); 
       WriteOutput(myFind); // Displays value of key c that is 3
</cfscript>

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