Files
opentf/website/docs/configuration/functions/element.html.md
Martin Atkins 1360948a41 website: document the functions "keys", "lookup", and "values"
I missed these on the first pass because in the legacy function table they
are, for some reason, added in a different place than the others.
2018-10-16 18:49:20 -07:00

942 B

layout, page_title, sidebar_current, description
layout page_title sidebar_current description
functions element function docs-funcs-collection-element The element function retrieves a single element from a list.

element Function

element 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.

Examples

> 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
  • index finds the index for a particular element value.
  • lookup retrieves a value from a map given its key.