Skip to content

Commit d461d41

Browse files
committed
update operator articles
1 parent 1ac0a11 commit d461d41

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

articles/azure-resource-manager/bicep/operators-access.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep accessor operators
33
description: Describes Bicep resource access operator and property access operator.
44
ms.topic: reference
55
ms.custom: devx-track-bicep
6-
ms.date: 02/12/2025
6+
ms.date: 05/20/2025
77
---
88

99
# Bicep accessor operators
@@ -13,6 +13,7 @@ The accessor operators are used to access child resources, properties on objects
1313
| Operator | Name |
1414
| ---- | ---- |
1515
| `[]` | [Index accessor](#index-accessor) |
16+
| `[^index]` | [Reverse index accessor](#reverse-index-accessor) |
1617
| `.` | [Function accessor](#function-accessor) |
1718
| `::` | [Nested resource accessor](#nested-resource-accessor) |
1819
| `.` | [Property accessor](#property-accessor) |
@@ -68,6 +69,52 @@ Output from the example:
6869
| ---- | ---- | ---- |
6970
| accessorResult | string | 'Development' |
7071

72+
## Reverse index accessor
73+
74+
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.
87+
88+
### Example
89+
90+
```bicep
91+
var items = [
92+
'apple'
93+
'banana'
94+
'orange'
95+
'grape'
96+
]
97+
98+
output secondToLast string = items[^2]
99+
```
100+
101+
Output from the example:
102+
103+
| Name | Type | Value |
104+
| ---- | ---- | ---- |
105+
| secondToLast | string | 'orange' |
106+
107+
```bicep
108+
var text = 'bicep'
109+
output secondToLastChar string = text[^2]
110+
```
111+
112+
Output from the example:
113+
114+
| Name | Type | Value |
115+
| ---- | ---- | ---- |
116+
| secondToLastChar | string | 'p' |
117+
71118
## Function accessor
72119

73120
`resourceName.functionName()`

articles/azure-resource-manager/bicep/operators.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep operators
33
description: Describes the Bicep operators available for Azure Resource Manager deployments.
44
ms.topic: reference
55
ms.custom: devx-track-bicep, devx-track-arm-template
6-
ms.date: 02/12/2025
6+
ms.date: 05/20/2025
77
---
88

99
# Bicep operators
@@ -46,6 +46,7 @@ The accessor operators are used to access nested resources and properties on obj
4646
| Operator | Name | Description |
4747
| ---- | ---- | ---- |
4848
| `[]` | [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). |
4950
| `.` | [Function accessor](./operators-access.md#function-accessor) | Call a function on a resource. |
5051
| `::` | [Nested resource accessor](./operators-access.md#nested-resource-accessor) | Access a nested resource from outside of the parent resource. |
5152
| `.` | [Property accessor](./operators-access.md#property-accessor) | Access properties of an object. |

0 commit comments

Comments
 (0)