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
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/data-types.md
+54-36Lines changed: 54 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Data types in Bicep
3
3
description: This article describes the data types that are available in Bicep.
4
4
ms.topic: reference
5
-
ms.date: 05/09/2025
5
+
ms.date: 05/20/2025
6
6
ms.custom: devx-track-bicep
7
7
---
8
8
@@ -12,7 +12,11 @@ This article describes the data types that are supported in [Bicep](./overview.m
12
12
13
13
## Arrays
14
14
15
-
Arrays start with a left bracket (`[`) and end with a right bracket (`]`). In Bicep, you can declare an array in a single line or in multiple lines. Commas (`,`) are used between values in single-line declarations, but they aren't used in multiple-line declarations. You can mix and match single-line and multiple-line declarations. The multiple-line declaration requires [Bicep CLI](./install.md#visual-studio-code-and-bicep-extension) version 0.7.X or later.
15
+
A **array** in Bicep is an ordered collection of values—such as strings, integers, objects, or even other arrays—commonly used to group related items like resource names, configuration settings, or parameters. Arrays are helpful for organizing deployment data, passing lists to resources, and iterating over multiple values.
16
+
17
+
Arrays in Bicep are immutable. Once declared, their contents can't be changed. To "modify" an array, create a new array using functions like [`concat`](./bicep-functions-array.md#concat), [`map`](./bicep-functions-lambda.md#map), or [`filter`](./bicep-functions-lambda.md#filter).
18
+
19
+
You can declare arrays in Bicep using either single-line or multi-line syntax. Multi-line array declarations require [Bicep CLI version 0.7.X or later](https://github.com/Azure/bicep/releases/tag/v0.7.4).
16
20
17
21
```bicep
18
22
var multiLineArray = [
@@ -27,9 +31,9 @@ var mixedArray = ['abc', 'def'
27
31
'ghi']
28
32
```
29
33
30
-
Each array element can be of any type. You can have an array where each item is the same data type, or an array that holds different data types.
34
+
**Single-line arrays** use commas (`,`) to separate values. **Multi-line arrays** don't use commas between values. You can mix single-line and multi-line declarations as needed.
31
35
32
-
The following example shows an array of integers and an array of different types.
36
+
Each array element can be of any type. You can have an array where each item is the same data type, or an array that holds different data types.
33
37
34
38
```bicep
35
39
var integerArray = [
@@ -44,27 +48,40 @@ var mixedArray = [
44
48
true
45
49
'example string'
46
50
]
51
+
52
+
var arrayOfObjects = [
53
+
{ name: 'dev', size: 1 }
54
+
{ name: 'prod', size: 2 }
55
+
]
47
56
```
48
57
49
-
Arrays in Bicep are based on zero. In the following example, the expression `exampleArray[0]` evaluates to 1 and `exampleArray[2]` evaluates to 3. The index of the indexer might be another expression. The expression `exampleArray[index]` evaluates to 2. Integer indexers are only allowed on the expression of array types.
58
+
Arrays in Bicep are zero-based. You can access elements by index:
50
59
51
60
```bicep
61
+
var exampleArray = [1, 2, 3]
62
+
output firstElement int = exampleArray[0] // 1
63
+
output thirdElement int = exampleArray[2] // 3
64
+
52
65
var index = 1
66
+
output secondElement int = exampleArray[index] // 2
67
+
```
53
68
54
-
var exampleArray = [
55
-
1
56
-
2
57
-
3
58
-
]
69
+
Starting with [Bicep CLI version 0.34.x](https://github.com/Azure/bicep/releases/tag/v0.34.1), you can use the `array[^index]` syntax to access elements from the end of an array — `^1` refers to the last element, `^2` to the second-to-last, and so on.
70
+
71
+
```bicep
72
+
var exampleArray = [1, 2, 3]
73
+
74
+
output lastElement int = exampleArray[^1] // 3
75
+
output secondToLastElement int = exampleArray[^2] // 2
59
76
```
60
77
61
-
You get the following error when the index is out of bounds:
78
+
If you access an index that is out of bounds, you get an error:
62
79
63
80
```error
64
81
The language expression property array index 'x' is out of bounds
65
82
```
66
83
67
-
To avoid this exception, use the [Or logical operator](./operators-logical.md#or-), as shown in the following example:
84
+
To avoid out-of-bounds exception, use the [Or logical operator](./operators-logical.md#or-), as shown in the following example:
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 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
+
`array[^index]`
77
+
78
+
If the index exceeds the length of the array, a compilation error occurs for static indices, or a runtime error occurs for dynamic indices.
79
+
80
+
For constant arrays, 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