StructFind

Finds and retrieves a top-level key from a string in a struct

Method Signature

StructFind(struct=[structloose], key=[any], defaultValue=[any])

Arguments

Argument
Type
Required
Description
Default

struct

struct

true

The struct object

key

any

true

The key to search

defaultValue

any

false

An optional value to be returned if the struct does not contain the key

Examples

Simple example

Searches through a structure by a given key and outputs the related value

Run Example

countries = { 
	"USA" : "Washington D.C.",
	"Germany" : "Berlin",
	"Japan" : "Tokio"
};
writeOutput( structFind( countries, "Germany" ) );

Result: Berlin

Additional Examples

Run Example

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 );

Last updated

Was this helpful?