github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/hcl2/functions/collection/element.mdx (about) 1 --- 2 layout: docs 3 page_title: element - Functions - Configuration Language 4 sidebar_title: element 5 description: The element function retrieves a single element from a list. 6 --- 7 8 # `element` Function 9 10 `element` retrieves a single element from a list. 11 12 ```hcl 13 element(list, index) 14 ``` 15 16 The index is zero-based. This function produces an error if used with an 17 empty list. 18 19 Use the built-in index syntax `list[index]` in most cases. Use this function 20 only for the special additional "wrap-around" behavior described below. 21 22 ## Examples 23 24 ```shell-session 25 > element(["a", "b", "c"], 1) 26 b 27 ``` 28 29 If the given index is greater than the length of the list then the index is 30 "wrapped around" by taking the index modulo the length of the list: 31 32 ```shell-session 33 > element(["a", "b", "c"], 3) 34 a 35 ``` 36 37 ## Related Functions 38 39 - [`index`](/docs/job-specification/hcl2/functions/collection/index-fn) finds the index for a particular element value. 40 - [`lookup`](/docs/job-specification/hcl2/functions/collection/lookup) retrieves a value from a _map_ given its _key_.