概要
從輸入傳回值的陣列。
語法
createArray(<inputValue>)
描述
函 createArray() 式會從輸入值傳回值的陣列。 您可以使用此函式來建立任何類型的陣列。 輸入值的類型必須相同 - 數位、字串、物件或陣列。 當輸入值為物件或陣列時,它們不需要是具有相同屬性或相同類型的陣列的物件。 當輸入值為陣列時,函式會傳回數位列的數位列。
範例
範例 1 - Create 整數陣列
範例 Synopsis
# createArray.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo array of integers
type: Microsoft.DSC.Debug/Echo
properties:
output: "[createArray(1, 3, 5)]"
dsc config get --file createArray.example.1.dsc.config.yaml config get
results:
- name: Echo array of integers
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
- 1
- 3
- 5
messages: []
hadErrors: false
範例 2 - Create 陣列陣列
此組態會傳回陣列,其中陣列中的專案也是陣列。 第一個子陣列只包含整數。 第二個子陣列只包含字串。
# createArray.example.2.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Create array of arrays
type: Microsoft.DSC.Debug/Echo
properties:
output: "[createArray(createArray(1,3,5), createArray('a', 'b', 'c'))]"
dsc config get --file createArray.example.2.dsc.config.yaml
results:
- name: Create array of arrays
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
- - 1
- 3
- 5
- - a
- b
- c
messages: []
hadErrors: false
範例 3 - Create 扁平化字串數位
此組態會使用 concat () 函式串連兩個新建立的字串陣列。 它會使用 YAML 的折疊多行字串語法,讓函式更容易閱讀。
# createArray.example.3.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo flattened array
type: Microsoft.DSC.Debug/Echo
properties:
output: >-
[concat(
createArray('a', 'b', 'c'),
createArray('d', 'e', 'f')
)]
dsc config get --file createArray.example.3.dsc.config.yaml
results:
- name: Echo flattened array
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output:
- a
- b
- c
- d
- e
- f
messages: []
hadErrors: false
參數
inputValue
函 createArray() 式需要相同類型的零個或多個輸入值。 以逗號分隔每個值。 如果任何輸入值的型別與第一個值不同,DSC 會傳回函式的錯誤。
Type: [integer, string, number, object, array]
Required: false
MinimumCount: 0
MaximumCount: 18446744073709551615
輸出
函式 createArray() 會傳回值的陣列。 當輸入值是陣列時,傳回的值是陣列的陣列,而不是輸入值的扁平化陣列。 您可以使用 concat () 函式傳回字串陣列的扁平化陣列,如 範例 3 所示。
Type: array