StructFind()
Determines the value associated with a key in a structure.
StructFind( struct=struct, key=string, defaultValue=any );
Returns: any
| Argument | Description |
|---|---|
|
struct
struct,
required
|
edit
Structure that contains the value to return Alias: structure, object |
|
key
string,
required
|
edit
Key whose value to return |
|
defaultValue
any,
optional
|
edit
Default value which will be returned if the key does not exist or if null was found |
Examples
editNon-Member Function
animals = {
cow: "moo",
pig: "oink",
cat: "meow"
};
// Show all animals
Dump(
label: "All animals",
var: animals
);
// Find cat in animals
findCat = StructFind(animals, "cat");
// Show results of findCat
Dump(
label: "Results of StructFind(animals, ""cat"")",
var: findCat
);
// If the key does not exist, we can set a default value. In this case a blank string.
findSnail = StructFind(animals, "snail", "");
// Show results of findSnail
Dump(
label: "Results of StructFind(animals, ""snail"", """")",
var: findSnail
);
See also
- Structures
- struct.find()
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)