---
title: Power Automateにおける配列について２
tags:  #power automate #power platform #array  
author: [Miyake Hideo](https://www.docswell.com/user/Miyake)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/DEYPXVKQEM.jpg?width=480
description: Power Automateにおける配列について２ by Miyake Hideo
published: June 23, 22
canonical: https://www.docswell.com/s/Miyake/K1EQLZ-2022-06-23-133834
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/DEYPXVKQEM.jpg)

Power Automate
における配列②
気ままに勉強会 #09


# Page. 2

![Page Image](https://bcdn.docswell.com/page/VJN51MR278.jpg)

今日の目標
関数を使って
配列を使いこなそう


# Page. 3

![Page Image](https://bcdn.docswell.com/page/YE9Y5NMDJ3.jpg)

アジェンダ
1. 配列（array）とは
2. 関数（function）とは
3. Power Automateの配列関数
4. Power Automateで配列操作


# Page. 4

![Page Image](https://bcdn.docswell.com/page/GE86YKL57D.jpg)

Miyake Mito
@MiTo60448639
https://qiita.com/MiyakeMito
https://www.icsoft.jp/


# Page. 5

![Page Image](https://bcdn.docswell.com/page/LEL94ZL3JR.jpg)

本日の参考サイト
■ Azure Logic Apps および Power Automate のワークフロー式関数のリファレン
ス ガイド
https://docs.microsoft.com/ja-jp/azure/logic-apps/workflow-definitionlanguage-functions-reference
■ Power Automateで文字列を1文字ずつに分割する方法
https://qiita.com/h-nagao/items/e0153b9a2c700cc2c95e
■ Power Automateでのソート (Loopなし)
https://qiita.com/h-nagao/items/765826be914fbf08bd02
■ Power Automate で配列をシャッフルする方法
https://mofumofupower.hatenablog.com/entry/2020/10/06/160200


# Page. 6

![Page Image](https://bcdn.docswell.com/page/4JMZKVMMEW.jpg)

配列（array）
とは


# Page. 7

![Page Image](https://bcdn.docswell.com/page/PJR6X2VL79.jpg)

配列とは ①
0
変数
1
2
3
4
5
• 変数（値を入れておく箱）が複数つながったもの
• それぞれの箱は、配列の「要素」と呼ばれます
• また配列の要素には、「添え字」という番号が割り当てられています
• Power Automateでは添え字を0から数えます


# Page. 8

![Page Image](https://bcdn.docswell.com/page/PEXM6DW67X.jpg)

配列とは ②
[ 1, 3, 2, 4, 0, 2 ]
• 一つの配列では、
同じ型のものしか扱えません
同じ性質の値だけをいれるようにします
• ブラケットで囲み、各アイテム（要素）はカンマで区切ります（JSON）
• データを取得する際は、添え字（何個目のデータ）を指定します
• Powe Automate は、文字列も一つ一つの文字の連続（＝配列）として
解釈できます


# Page. 9

![Page Image](https://bcdn.docswell.com/page/3EKG1XVGJD.jpg)

配列とは ③
■ おや・・・？
宛先
ぶき
ぼうぐ
クリスタル
レイク
クリスタル
レイク
クリスタル
レイク
N.Y.
研究所
宇宙船
JSON パンダ男
JSON パンダ子
JSON パン太郎
JSON パンダ美
JSON パン助
JSON パンダ


# Page. 10

![Page Image](https://bcdn.docswell.com/page/L73NQ5M575.jpg)

[
配列とは ④
{&quot;宛先&quot;:
{&quot;住所&quot;:&quot;クリスタルレイク&quot;,&quot;名前&quot;:&quot;JSON パンダ男&quot;},
&quot;ぶき&quot;:
{&quot;オノ&quot;:1,&quot;チェーンソー&quot;:3},
&quot;ぼうぐ&quot;:
{&quot;マスク&quot;:1}
• 各要素は、オブジェクトや配列で指
定することも可能です
},
{&quot;宛先&quot;:
{&quot;住所&quot;:&quot;クリスタルレイク&quot;,&quot;名前&quot;:&quot;JSON パンダ子&quot;},
&quot;ぶき&quot;:
{&quot;オノ&quot;:2,&quot;チェーンソー&quot;:1},
&quot;ぼうぐ&quot;:
{&quot;マスク&quot;:3}
[
},
[1,2,3],
---- 中略----
[4,5,6,7],
[8,9]
{&quot;宛先&quot;:
{&quot;住所&quot;:&quot;宇宙船&quot;,&quot;名前&quot;:&quot;JSON パンダ&quot;},
]
&quot;ぶき&quot;:
{&quot;オノ&quot;:1,&quot;チェーンソー&quot;:0},
&quot;ぼうぐ&quot;:
{&quot;マスク&quot;:2}
}
]


# Page. 11

![Page Image](https://bcdn.docswell.com/page/87DW9D6YJG.jpg)

関数（function）
とは


# Page. 12

![Page Image](https://bcdn.docswell.com/page/VJP9ZXY2E8.jpg)

関数とは ①
■ 関数とは自動販売機のようなものである
引数（Input）
関数（function）
戻り値（Output）


# Page. 13

![Page Image](https://bcdn.docswell.com/page/2EVMWLGXEQ.jpg)

関数とは ②
■ 関数とは自動販売機のようなものである
createArray()
（１，３，２）
createArray()
[１，３，２]


# Page. 14

![Page Image](https://bcdn.docswell.com/page/57GGDX8R7L.jpg)

Power Automate
の配列関数
変換関数


# Page. 15

![Page Image](https://bcdn.docswell.com/page/4EQX189Y7P.jpg)

配列を作る
⚫ array()
1 つの入力から配列を返します
⚫ createArray()
複数の入力から配列を作成して返します
１つの入力からも作成可能なので
➢ 常にcreateArray()を推奨
➢ アクションの[変数を初期化する]や[作成]でも作成可能


# Page. 16

![Page Image](https://bcdn.docswell.com/page/KJ46R2XZ71.jpg)

Power Automate
の配列関数
コレクション関数


# Page. 17

![Page Image](https://bcdn.docswell.com/page/LE1VQMND7G.jpg)

配列を捜索する
⚫ contains()
コレクションに特定の項目があるかどうかを確認します
⚫ empty()
コレクションが空かどうかを調べます
⚫ length()
文字列または配列内の項目の数を返します
➢ 文字列の場合、全角も半角も１として数える
(サロゲートペア（UTF-16)は２)


# Page. 18

![Page Image](https://bcdn.docswell.com/page/GEWLM34872.jpg)

配列から要素を取得する
⚫ first()
コレクションから最初の項目を返します
⚫ last()
コレクションから最後の項目を返します


# Page. 19

![Page Image](https://bcdn.docswell.com/page/47ZMQV29E3.jpg)

配列から要素を取得する
⚫ skip()
コレクションの先頭から項目を削除し、&quot;他のすべて&quot; の項
目を返します
⚫ take()
コレクションの先頭から項目を返します
➢ パラメータがStringの場合は substring() で代用可


# Page. 20

![Page Image](https://bcdn.docswell.com/page/YJ6N65VDJV.jpg)

配列から要素を取得する
⚫ join()
配列の &quot;すべて&quot; の項目を含み、指定された区切り記号で
各項目が区切られた、文字列を返します
➢ [結合]と同じ


# Page. 21

![Page Image](https://bcdn.docswell.com/page/GJ556YD8J4.jpg)

配列から要素を取得する
⚫ intersection()
指定したコレクションすべてに共通する項目 &quot;のみ&quot; を含む
コレクションを返します
[
],[
],[
]
[
]
⚫ union()
指定した複数のコレクションの &quot;すべての&quot; 項目を含む 1 つの
コレクションを返します
[
],[
],[
]
[
]


# Page. 22

![Page Image](https://bcdn.docswell.com/page/LE3NQ5MGE5.jpg)

配列から要素を取得する
⚫ item()
配列に対する繰り返しアクションの内部で使うと、アク
ションの現在の繰り返しの間に配列の現在の項目を返しま
す
[データ操作]-[選択]や
Apply to each で
[アレイのフィルター処理]


# Page. 23

![Page Image](https://bcdn.docswell.com/page/8EDW9D6N7G.jpg)

Power Automate
の配列関数
文字列関数


# Page. 24

![Page Image](https://bcdn.docswell.com/page/V7P9ZXYNJ8.jpg)

配列から要素を取得する
⚫ split()
元の文字列で指定された区切り文字に基づいたより大きい
文字列から、コンマで区切られた部分文字列を含む配列を
返します
⚫ replace()
部分文字列を指定した文字列で置換し、更新された文字列
を返します


# Page. 25

![Page Image](https://bcdn.docswell.com/page/2JVMWLGYJQ.jpg)

Power Automate
の配列関数
算術関数


# Page. 26

![Page Image](https://bcdn.docswell.com/page/5EGGDX8WEL.jpg)

配列から要素を取得する
⚫ max()
123
数値のセットまたは配列から最大の値を返します
⚫ min()
123
数値のセットまたは配列から最小の値を返します
⚫ range()
指定した整数から始まる整数の配列を返します


# Page. 27

![Page Image](https://bcdn.docswell.com/page/4JQX189QEP.jpg)

Power Automate
の配列関数
JSON関数


# Page. 28

![Page Image](https://bcdn.docswell.com/page/K746R2XYE1.jpg)

配列から要素を取得する
⚫ addProperty()
JSON オブジェクトにプロパティとその値または名前と値
のペアを追加し、更新されたオブジェクトを返します
⚫ setProperty()
JSON オブジェクトのプロパティの値を設定し、更新され
たオブジェクトを返します
⚫ removeProperty()
JSON オブジェクトからプロパティを削除し、更新された
オブジェクトを返します


# Page. 29

![Page Image](https://bcdn.docswell.com/page/LJ1VQMNNEG.jpg)

Power Automate
で配列操作
応用編


# Page. 30

![Page Image](https://bcdn.docswell.com/page/GJWLMDMME2.jpg)

Power Automateで配列操作
[データ操作]
［関数]
item()
range()
substring()
union()
可能性（出来ること）が無限大


# Page. 31

![Page Image](https://bcdn.docswell.com/page/4EZMQGQMJ3.jpg)

文字列を1文字ずつに分割
range(0,length(outputs(&#039;target_text&#039;)))
substring(outputs(&#039;target_text&#039;),item(),1)


# Page. 32

![Page Image](https://bcdn.docswell.com/page/Y76N6Y657V.jpg)

配列をソート ①
■ ソートマッピングを作成
range(0, length(outputs(&#039;mapping_text&#039;)))
substring(outputs(&#039;mapping_Text&#039;),item(),1)


# Page. 33

![Page Image](https://bcdn.docswell.com/page/G7556G6G74.jpg)

配列をソート ②
■ ソートマッピングを基にソート
output(‘mapping_array’)
output(‘target_array’)
Item()


# Page. 34

![Page Image](https://bcdn.docswell.com/page/9J2NMYMDER.jpg)

配列をシャッフル ①
■ ターゲットの要素数×100個の、0~要素数のランダムな
数字を含む配列を作成
range(0,mul(length(outputs(&#039;target_array&#039;)),100))
rand(0,length(outputs(&#039;target_array&#039;)))


# Page. 35

![Page Image](https://bcdn.docswell.com/page/DEYPXGXMEM.jpg)

配列をシャッフル ②
■ Union()で出力される配列は、第一引数の要素順になります
union(body(&#039;random_array_work&#039;),range(0,length(outputs(&#039;target_array&#039;))))


# Page. 36

![Page Image](https://bcdn.docswell.com/page/VJN51G1378.jpg)

配列をシャッフル ③
■ 生成したランダムな配列を、添え字として指定
outputs(‘random_array&#039;)
outputs(&#039;target_array&#039;)?[item()]


# Page. 37

![Page Image](https://bcdn.docswell.com/page/YE9Y5W5PJ3.jpg)

Power Automate と
Power Virtual Agents で
ゲームを作ってます
⚫ オセロ
⚫ 神経衰弱
⚫ どうぶつしょうぎ
➢ 公開中
https://github.com/MiyakeMito/Repository
➢ インポート手順
https://qiita.com/MiyakeMito/items/b2df9ca9832fbce26a0d


# Page. 38

![Page Image](https://bcdn.docswell.com/page/GE86YNYX7D.jpg)

まとめ
配列は便利
配列を制するとPower Automateが
もっと楽しくなる
使いこなして面白フローをつくろう！


# Page. 39

![Page Image](https://bcdn.docswell.com/page/LEL94P4NJR.jpg)

ありがとうございました


