# 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](https://try.boxlang.io/?code=eJxLzi%2FNKynKTC1WsFWoVuDiVAoNdlRSsFJQCk8szsjMSy%2FJz1Nw0XPWU9IByrmnFuUm5lWC5Z1Si3Iy88DCXokFiXlgwZD87Mx8Ja5aa67yosySVP%2FSkoLSEg2F4pKi0uQSt8y8FA2FZJiFOgoI8zQVNK25AEUEKg0%3D)

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

```

Result: Berlin

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJyVj8FOwzAQRM%2FNV4x8aqWovYNyqIKKcmpFkDhvmw214tgodggI8e%2FYTkroASSOu7P7Zoa0bElZZPhAssj3T7iBaI0RabI4FPdhMlI3Ycy3j1FkM4jk8zbZbFCezQBSCjRikru%2BfVlC0ZFVJrazIFK8UpdNE1bxeyd1hRM5SP0NqP0u96sMpev6kws3y4uaQvhzMb1H845tr5yFqTG9Xmd4mPUfwJkXgWI15bu4jwZFDXdmNPyOyrCFNg78Jq1LMbAPrmHZgVBxTd7EE1TPaxTav0nrDyx79ahIN7Cuk%2Fp5HfuVmqT6taENqgjR%2FugZEf9sOoIj%2BbrxmMebfQGdfacH)

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

```

## Related

* [StructAppend](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structappend)
* [StructClear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structclear)
* [StructCopy](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structcopy)
* [StructDelete](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structdelete)
* [StructEach](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structeach)
* [StructEquals](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structequals)
* [StructEvery](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structevery)
* [StructFilter](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structfilter)
* [StructFindKey](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structfindkey)
* [StructFindValue](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structfindvalue)
* [StructGet](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structget)
* [StructGetMetadata](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structgetmetadata)
* [StructInsert](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structinsert)
* [StructIsCaseSensitive](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structiscasesensitive)
* [StructIsOrdered](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structisordered)
* [StructKeyArray](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structkeyarray)
* [StructKeyExists](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structkeyexists)
* [StructKeyList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structkeylist)
* [StructKeyTranslate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structkeytranslate)
* [StructMap](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structmap)
* [StructNew](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structnew)
* [StructNone](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structnone)
* [StructReduce](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structreduce)
* [StructSome](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structsome)
* [StructSort](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structsort)
* [StructToQueryString](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structtoquerystring)
* [StructToSorted](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structtosorted)
* [StructUpdate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structupdate)
* [StructValueArray](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structvaluearray)
