---
schema_version: "1"
id: a3f5ec4a76cea96df4af3c3fe6afc6bab3c0265bcc088656a181a4bb1fc5a142
title: flatten
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.5/dw-core-functions-flatten.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.5/dw-core-functions-flatten
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 14df45b01f91e27c5654be42f5da99377ebaa3f79960404c517cb1ce399a201c
description: MuleSoft Documentation Site
release: "2.5"
latest: false
---
# flatten

## [](#flatten1)flatten<T, Q>(@StreamCapable items: Array<Array<T> | Q>): Array<T | Q>

一連のサブ配列 (​`[ [1,2,3], [4,5,[6]], [], [null] ]`​ など) を 1 つのフラット化した配列 (​`[ 1, 2, 3, 4, 5, [6], null ]`​ など) に変換します。

サブ配列の最初のレベルのみがフラット化され、空のサブ配列は省略されます。

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

<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>
</tbody>
</table>

### [](#例)例

この例では、数値の配列を 3 つ定義し、それらの 3 つの配列を含むもう 1 つの配列を作成してから、flatten 関数を使用して配列の配列をすべての値を含む 1 つの配列に変換します。

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

```DataWeave
%dw 2.0
output application/json
var array1 = [1,2,3]
var array2 = [4,5,6]
var array3 = [7,8,9]
var arrayOfArrays = [array1, array2, array3]
---
flatten(arrayOfArrays)
```

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

```JSON
[ 1,2,3,4,5,6,7,8,9 ]
```

### [](#例-2)例

次の例では、オブジェクトのネストされた配列から 1 つの配列を返します。

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

```DataWeave
%dw 2.0
var myData =
{ user : [
   {
     group : "dev",
     myarray : [
       { name : "Shoki", id : 5678 },
       { name : "Mariano", id : 9123 }
     ]
   },
   {
     group : "test",
     myarray : [
       { name : "Sai", id : 2001 },
       { name : "Peter", id : 2002 }
     ]
   }
 ]
}
output application/json
---
flatten(myData.user.myarray)
```

#### [](#出力-2)出力

```JSON
[
  {
    "name": "Shoki",
    "id": 5678
  },
  {
    "name": "Mariano",
    "id": 9123
  },
  {
    "name": "Sai",
    "id": 2001
  },
  {
    "name": "Peter",
    "id": 2002
  }
]
```

`flatten(myData.user.myarray)`​ を使用するのではなく、​`myData.user.myarray`​ を使用して ​`myarray`​ 内のオブジェクトの配列を選択した場合、出力はオブジェクトのネストされた配列になります。

```JSON
[
  [
    {
      "name": "Shoki",
      "id": 5678
    },
    {
      "name": "Mariano",
      "id": 9123
    }
  ]
]
```

## [](#flatten2)flatten(@StreamCapable value: Null): Null

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