---
schema_version: "1"
id: e8d747a3fe9ef2b818e68c803f0e099c3a36d5bc0694d78f87806e21d336aa54
title: takeWhile
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.5/dw-arrays-functions-takewhile.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.5/dw-arrays-functions-takewhile
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 794d9cc3dbb38b78f10751951cd04b76888bf53f8a4ee5096bf1b78422c8b804
description: MuleSoft Documentation Site
release: "2.5"
latest: false
---
# takeWhile

## [](#takewhile1)takeWhile<T>(array: Array<T>, condition: (item: T) -> Boolean): Array<T>

条件を満たす場合に要素を配列から選択しますが、条件を満たさない要素に達したら選択プロセスを停止します。

条件を満たすすべての要素を選択するには、​`filter`​ 関数を使用します。

_DataWeave バージョン 2.2.0 で導入されました。_

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

<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>array</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>condition</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">配列の要素の照合に使用される条件 (式)。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、配列内の要素を反復処理し、インデックスが ​`<= 1`​ の要素のみを選択し、​`2`​ より大きい要素に達したら要素の選択を停止します。配列内で ​`2`​ が前にあるため、2 つ目の ​`1`​ は選択されません。この関数は、結果を配列に出力します。

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

```DataWeave
%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,1,2,1]
---
arr takeWhile $ <= 1
```

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

```json
[
  0,
  1
]
```

## [](#takewhile2)takeWhile(array: Null, condition: (item: Nothing) -> Any): Null

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

_DataWeave バージョン 2.4.0 で導入されました。_