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
+63-34Lines changed: 63 additions & 34 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,21 @@ 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:
-**Single-line arrays** use commas (`,`) to separate values.
27
+
-**Multi-line arrays** don't use commas between values.
28
+
- You can mix single-line and multi-line declarations as needed.
29
+
- Multi-line array declarations require [Bicep CLI](./install.md#visual-studio-code-and-bicep-extension) version 0.7.X or later.
16
30
17
31
```bicep
18
32
var multiLineArray = [
@@ -27,9 +41,10 @@ var mixedArray = ['abc', 'def'
27
41
'ghi']
28
42
```
29
43
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.
44
+
Each array element can be of any type. Arrays can be:
31
45
32
-
The following example shows an array of integers and an array of different types.
46
+
-**Homogeneous** (all elements of the same type)
47
+
-**Heterogeneous** (elements of different types)
33
48
34
49
```bicep
35
50
var integerArray = [
@@ -44,27 +59,40 @@ var mixedArray = [
44
59
true
45
60
'example string'
46
61
]
62
+
63
+
var arrayOfObjects = [
64
+
{ name: 'dev', size: 1 }
65
+
{ name: 'prod', size: 2 }
66
+
]
47
67
```
48
68
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.
69
+
Arrays in Bicep are zero-based. You can access elements by index:
50
70
51
71
```bicep
72
+
var exampleArray = [1, 2, 3]
73
+
output firstElement int = exampleArray[0] // 1
74
+
output thirdElement int = exampleArray[2] // 3
75
+
52
76
var index = 1
77
+
output secondElement int = exampleArray[index] // 2
78
+
```
53
79
54
-
var exampleArray = [
55
-
1
56
-
2
57
-
3
58
-
]
80
+
The `array[^index]` syntax allows you to access elements from the end of the array, where `^1` is the last element, `^2` is the second-to-last, and so on.
81
+
82
+
```bicep
83
+
var exampleArray = [1, 2, 3]
84
+
85
+
output lastElement int = exampleArray[^1] // 3
86
+
output secondToLastElement int = exampleArray[^2] // 2
59
87
```
60
88
61
-
You get the following error when the index is out of bounds:
89
+
If you access an index that is out of bounds, you get an error:
62
90
63
91
```error
64
92
The language expression property array index 'x' is out of bounds
65
93
```
66
94
67
-
To avoid this exception, use the [Or logical operator](./operators-logical.md#or-), as shown in the following example:
95
+
To avoid out-of-bounds exception, use the [Or logical operator](./operators-logical.md#or-), as shown in the following example:
0 commit comments