跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

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 ​

shellsession
> 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:

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

基于 MPL-2.0 许可证发布。