You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Beginning with [Bicep CLI version 0.34.x](https://github.com/Azure/bicep/releases/tag/v0.34.1), the reverse index accessor operator (`^`) allows you to retrieve an element from an array or a character from a string by counting from the end. This one-based index means `^1` returns the last item, `^2` the second-to-last, and so on. The index must be a positive integer greater than zero and can be specified as a literal or an expression that evaluates to an integer.
75
+
76
+
```bicep
77
+
array[^index]
78
+
string[^index]
79
+
```
80
+
81
+
### Remarks
82
+
83
+
- The reverse index operator provides a convenient way to access elements or characters from the end of a sequence without calculating its length.
84
+
- The index must be at least 1. Using `^0` results in a compilation error.
85
+
- If the index exceeds the length of the array or string, a compilation error occurs for static indices, or a runtime error occurs for dynamic indices.
86
+
- For constant arrays or strings, the operator is evaluated at compile time. For dynamic inputs, such as [parameters](./parameters.md), evaluation occurs at deployment time.
@@ -46,6 +46,7 @@ The accessor operators are used to access nested resources and properties on obj
46
46
| Operator | Name | Description |
47
47
| ---- | ---- | ---- |
48
48
|`[]`|[Index accessor](./operators-access.md#index-accessor)| Access an element of an array or property on an object. |
49
+
|`[^index]`|[Reverse index accessor](./operators-access.md#reverse-index-accessor)| Accesses an array element by index, counting from the end of the array (1-based from the end). |
49
50
|`.`|[Function accessor](./operators-access.md#function-accessor)| Call a function on a resource. |
50
51
|`::`|[Nested resource accessor](./operators-access.md#nested-resource-accessor)| Access a nested resource from outside of the parent resource. |
51
52
|`.`|[Property accessor](./operators-access.md#property-accessor)| Access properties of an object. |
0 commit comments