Skip to content

Commit cf251f6

Browse files
committed
fix element function documentation
1 parent 9bbe34d commit cf251f6

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

website/docs/language/functions/element.mdx

+6-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ element(list, index)
1212
```
1313

1414
The index is zero-based. This function produces an error if used with an
15-
empty list. The index must be a non-negative integer.
15+
empty list. The index can be a negative integer.
1616

1717
Use the built-in index syntax `list[index]` in most cases. Use this function
1818
only for the special additional "wrap-around" behavior described below.
@@ -21,24 +21,22 @@ only for the special additional "wrap-around" behavior described below.
2121

2222
```
2323
> element(["a", "b", "c"], 1)
24-
b
24+
"b"
2525
```
2626

2727
If the given index is greater than the length of the list then the index is
2828
"wrapped around" by taking the index modulo the length of the list:
2929

3030
```
3131
> element(["a", "b", "c"], 3)
32-
a
32+
"a"
3333
```
3434

35-
To get the last element from the list use [`length`](/terraform/language/functions/length) to find
36-
the size of the list (minus 1 as the list is zero-based) and then pick the
37-
last element:
35+
To get the last element from the list use the index `-1`:
3836

3937
```
40-
> element(["a", "b", "c"], length(["a", "b", "c"])-1)
41-
c
38+
> element(["a", "b", "c"], -1)
39+
"c"
4240
```
4341

4442
## Related Functions

0 commit comments

Comments
 (0)