mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 18:05:42 +03:00
docs: fixup HCL2 index collection function documentation. (#13511)
This commit is contained in:
@@ -1,25 +1,30 @@
|
||||
---
|
||||
layout: docs
|
||||
page_title: index - Functions - Configuration Language
|
||||
description: The index function finds the element index for a given value in a list.
|
||||
description: |-
|
||||
The index function returns an element from the given list or map
|
||||
using the given index or key.
|
||||
---
|
||||
|
||||
# `index` Function
|
||||
|
||||
`index` finds the element index for a given value in a list.
|
||||
`index` finds the element at the index when handling lists, or the element at
|
||||
the key when handling maps.
|
||||
|
||||
```hcl
|
||||
index(list, value)
|
||||
```
|
||||
|
||||
The returned index is zero-based. This function produces an error if the given
|
||||
value is not present in the list.
|
||||
|
||||
## Examples
|
||||
|
||||
```shell-session
|
||||
> index(["a", "b", "c"], "b")
|
||||
1
|
||||
> index(["a", "b", "c"], 1)
|
||||
"b"
|
||||
```
|
||||
|
||||
```shell-session
|
||||
> index({"a"=1, "c"=2, "d"=3}, "c")
|
||||
2
|
||||
```
|
||||
|
||||
## Related Functions
|
||||
|
||||
Reference in New Issue
Block a user