website/content/docs/templates/hcl_templates/functions/collection/element.mdx
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
[!IMPORTANT]
Documentation Update: Product documentation previously located in/websitehas moved to thehashicorp/web-unified-docsrepository, where all product documentation is now centralized. Please make contributions directly toweb-unified-docs, since changes to/websitein this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
element Functionelement retrieves a single element from a list.
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.
> 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:
> element(["a", "b", "c"], 3)
a