2018-06-02 03:56:34 +02:00
|
|
|
---
|
2021-12-15 03:41:17 +01:00
|
|
|
page_title: lookup - Functions - Configuration Language
|
|
|
|
description: The lookup function retrieves an element value from a map given its key.
|
2018-06-02 03:56:34 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# `lookup` Function
|
|
|
|
|
|
|
|
`lookup` retrieves the value of a single element from a map, given its key.
|
2020-11-06 14:58:33 +01:00
|
|
|
If the given key does not exist, the given default value is returned instead.
|
2018-06-02 03:56:34 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
lookup(map, key, default)
|
|
|
|
```
|
|
|
|
|
|
|
|
-> For historical reasons, the `default` parameter is actually optional. However,
|
|
|
|
omitting `default` is deprecated since v0.7 because that would then be
|
|
|
|
equivalent to the native index syntax, `map[key]`.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
|
|
|
> lookup({a="ay", b="bee"}, "a", "what?")
|
|
|
|
ay
|
|
|
|
> lookup({a="ay", b="bee"}, "c", "what?")
|
|
|
|
what?
|
|
|
|
```
|
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
2021-12-15 03:41:17 +01:00
|
|
|
* [`element`](/language/functions/element) retrieves a value from a _list_ given its _index_.
|