Skip to content

Commit 6633fe0

Browse files
committed
Add the syntax
1 parent bd21639 commit 6633fe0

File tree

1 file changed

+63
-34
lines changed

1 file changed

+63
-34
lines changed

articles/azure-resource-manager/bicep/data-types.md

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Data types in Bicep
33
description: This article describes the data types that are available in Bicep.
44
ms.topic: reference
5-
ms.date: 05/09/2025
5+
ms.date: 05/20/2025
66
ms.custom: devx-track-bicep
77
---
88

@@ -12,7 +12,21 @@ This article describes the data types that are supported in [Bicep](./overview.m
1212

1313
## Arrays
1414

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:
20+
21+
| Syntax | Example |
22+
| -------------- | -------------------------------------------- |
23+
| Single-line | `var arr = ['a', 'b', 'c']` |
24+
| Multi-line | <pre>var arr = [<br> 'a'<br> 'b'<br> 'c'<br>]</pre> |
25+
26+
- **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.
1630

1731
```bicep
1832
var multiLineArray = [
@@ -27,9 +41,10 @@ var mixedArray = ['abc', 'def'
2741
'ghi']
2842
```
2943

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:
3145

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)
3348

3449
```bicep
3550
var integerArray = [
@@ -44,27 +59,40 @@ var mixedArray = [
4459
true
4560
'example string'
4661
]
62+
63+
var arrayOfObjects = [
64+
{ name: 'dev', size: 1 }
65+
{ name: 'prod', size: 2 }
66+
]
4767
```
4868

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:
5070

5171
```bicep
72+
var exampleArray = [1, 2, 3]
73+
output firstElement int = exampleArray[0] // 1
74+
output thirdElement int = exampleArray[2] // 3
75+
5276
var index = 1
77+
output secondElement int = exampleArray[index] // 2
78+
```
5379

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
5987
```
6088

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:
6290

6391
```error
6492
The language expression property array index 'x' is out of bounds
6593
```
6694

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:
6896

6997
```bicep
7098
param emptyArray array = []
@@ -76,15 +104,15 @@ output bar bool = length(numberArray) <= 3 || numberArray[3] == 4
76104

77105
### Array-related operators
78106

79-
* Use [Comparison operators](./operators-comparison.md) to compare two arrays.
80-
* Use [Index accessor](./operators-access.md#index-accessor) to get an element from an array.
81-
* Use [Safe-dereference operator](./operator-safe-dereference.md) to access elements of an array.
82-
* Use [Spread](./operator-spread.md) to merge arrays.
107+
- Use [Comparison operators](./operators-comparison.md) to compare two arrays.
108+
- Use [Index accessor](./operators-access.md#index-accessor) to get an element from an array.
109+
- Use [Safe-dereference operator](./operator-safe-dereference.md) to access elements of an array.
110+
- Use [Spread](./operator-spread.md) to merge arrays.
83111

84112
### Array-related functions
85113

86-
* See [Array functions](./bicep-functions-array.md).
87-
* See [Lambda functions](./bicep-functions-lambda.md).
114+
- See [Array functions](./bicep-functions-array.md).
115+
- See [Lambda functions](./bicep-functions-lambda.md).
88116

89117
## Booleans
90118

@@ -96,8 +124,8 @@ param exampleBool bool = true
96124

97125
## Boolean-related operators
98126

99-
* Use [Comparison operators](./operators-comparison.md) to compare boolean values.
100-
* See [Logical operators](./operators-logical.md).
127+
- Use [Comparison operators](./operators-comparison.md) to compare boolean values.
128+
- See [Logical operators](./operators-logical.md).
101129

102130
## Boolean-related functions
103131

@@ -140,8 +168,8 @@ Floating point, decimal, or binary formats aren't currently supported.
140168

141169
### Integer-related operators
142170

143-
* See [Comparison operators](./operators-comparison.md).
144-
* See [Numeric operators](./operators-numeric.md).
171+
- See [Comparison operators](./operators-comparison.md).
172+
- See [Numeric operators](./operators-numeric.md).
145173

146174
### Integer-related functions
147175

@@ -237,10 +265,10 @@ output bar bool = contains(objectToTest, 'four') && objectToTest.four == 4
237265

238266
### Object-related operators
239267

240-
* Use [Comparison operators](./operators-comparison.md) to compare objects.
241-
* Use [Index accessor](./operators-access.md#index-accessor) to get a property from an object.
242-
* Use [Safe-dereference operator](./operator-safe-dereference.md) to access object members.
243-
* Use [Spread](./operator-spread.md) to merge objects.
268+
- Use [Comparison operators](./operators-comparison.md) to compare objects.
269+
- Use [Index accessor](./operators-access.md#index-accessor) to get a property from an object.
270+
- Use [Safe-dereference operator](./operator-safe-dereference.md) to access object members.
271+
- Use [Spread](./operator-spread.md) to merge objects.
244272

245273
### Object-related functions
246274

@@ -348,10 +376,11 @@ is ${blocked}'''
348376

349377
### String-related operators
350378

351-
* See [Comparison operators](./operators-comparison.md).
379+
- See [Comparison operators](./operators-comparison.md).
352380

353381
### String-related functions
354382

383+
- See [String functions](./bicep-functions-string.md).
355384

356385
## Union types
357386

@@ -408,14 +437,14 @@ The parameter value is validated based on the discriminated property value. For
408437

409438
The union type has some limitations:
410439

411-
- Union types must be reducible to a single Azure Resource Manager type. The following definition is invalid:
412-
413-
```bicep
414-
type foo = 'a' | 1
415-
```
440+
- Union types must be reducible to a single Azure Resource Manager type. The following definition is invalid:
441+
442+
```bicep
443+
type foo = 'a' | 1
444+
```
416445

417-
- Only literals are permitted as members.
418-
- All literals must be of the same primitive data type (for example, all strings or all integers).
446+
- Only literals are permitted as members.
447+
- All literals must be of the same primitive data type (for example, all strings or all integers).
419448

420449
You can use the union type syntax in [user-defined data types](./user-defined-data-types.md).
421450

0 commit comments

Comments
 (0)