次の方法で共有


createArray

概要

入力から値の配列を返します。

構文

createArray(<inputValue>)

説明

関数は createArray() 、入力値から値の配列を返します。 この関数を使用すると、任意の型の配列を作成できます。 入力値は、数値、文字列、オブジェクト、または配列と同じ型である必要があります。 入力値がオブジェクトまたは配列の場合、同じプロパティまたは同じ型の配列を持つオブジェクトである必要はありません。 入力値が配列の場合、関数は配列の配列を返します。

例 1 - 整数の配列をCreateする

概要の例

# 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する

この構成では、配列内の項目も配列である配列が返されます。 最初のサブ配列には整数のみが含まれます。 2 番目のサブ配列には文字列のみが含まれます。

# 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() 関数を使用して、新しく作成された 2 つの文字列配列を連結します。 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() 、同じ型の 0 個以上の入力値を受け取ります。 各値をコンマで区切ります。 入力値の型が最初の値と異なる場合、DSC は関数のエラーを返します。

Type:         [integer, string, number, object, array]
Required:     false
MinimumCount: 0
MaximumCount: 18446744073709551615

出力

関数は createArray() 値の配列を返します。 入力値が配列の場合、戻り値は配列の配列であり、入力値のフラット化された配列ではありません。 例 3 のように、concat() 関数を使用して文字列配列のフラット化された配列を返すことができます。

Type: array