Zachary Shilton 830140157d
website: remove obselete nav data (#10811)
* website: remove obselete sidebar_title frontmatter from docs

* website: bump to latest docs-page

* website: update plugin creation and registration docs

* website: fix broken links
2021-03-31 15:07:00 -04:00

39 lines
1011 B
Plaintext

---
page_title: element - Functions - Configuration Language
description: The element function retrieves a single element from a list.
---
# `element` Function
`element` retrieves a single element from a list.
```hcl
element(list, index)
```
The index is zero-based. This function produces an error if used with an
empty list.
Use the built-in index syntax `list[index]` in most cases. Use this function
only for the special additional "wrap-around" behavior described below.
## Examples
```shell-session
> element(["a", "b", "c"], 1)
b
```
If the given index is greater than the length of the list then the index is
"wrapped around" by taking the index modulo the length of the list:
```shell-session
> element(["a", "b", "c"], 3)
a
```
## Related Functions
- [`index`](/docs/templates/hcl_templates/functions/collection/index-fn) finds the index for a particular element value.
- [`lookup`](/docs/templates/hcl_templates/functions/collection/lookup) retrieves a value from a _map_ given its _key_.