---
schema_version: "1"
id: 9c520f2d5dd351b9f0e97cc5def637bb5712957b89413edf1227ed1f03dd67f1
title: flatMap
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.6/dw-core-functions-flatmap.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.6/dw-core-functions-flatmap
source_site: docs.mulesoft.com
content_type: documentation
content_hash: bfc4a447aaed2253b8d6c91ded6716b7ec04bf4893636f5a4bb5a3d4de4375ae
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
# flatMap

## [](#flatmap1)flatMap<T, R>(@StreamCapable items: Array<T>, mapper: (item: T, index: Number) -> Array<R>): Array<R>

配列内の各項目を反復処理し、結果をフラット化します。

(​`[ [1,2], [3,4] ]`​ などの入力内の値を反復処理する場合の ​`map`​ のように) 配列の配列を返すのではなく、​`flatMap`​ は ​`[1, 2, 3, 4]`​ のようにフラット化された配列を返します。 ​`flatMap`​ は ​`flatten`​ に似ていますが、​`flatten`​ は配列の値でのみ動作し、​`flatMap`​ は配列の項目の値とインデックスで動作できます。

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>items</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">マップする配列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>mapper</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">フラット化する、配列内の ​<code>item</code>​ または ​<code>index</code>​ の式またはセレクター。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、各値が順序どおりに含まれる配列を返します。これは、省略可能な ​`index`​ パラメーターを匿名関数内で指定していますが (​`(value, index) → value`​)、​`index`​ を出力のセレクターとして使用しません。このため、​`(value) → value`​ を使用して匿名関数を記述することができます。値の代わりに匿名パラメーターを使用して、この例を ​`[ [3,5], [0.9,5.5] ] flatMap $`​ のように記述することもできます。 次の例では、​`flatten`​ を使用する ​`flatten([ [3,5], [0.9,5.5] ])`​ と同じ結果が生成されます。

#### [](#ソース)ソース

```DataWeave
%dw 2.0
output application/json
---
[ [3,5], [0.9,5.5] ] flatMap (value, index) -> value
```

#### [](#出力)出力

```JSON
[ 3, 5, 0.9, 5.5]
```

## [](#flatmap2)flatMap<T, R>(@StreamCapable value: Null, mapper: (item: Nothing, index: Nothing) -> Any): Null

`flatMap`​ を ​`null`​ 値に使用できるようにするヘルパー関数。