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

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

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

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

_DataWeave 2.2.0 で導入されました。Mule 4.2 以降でサポートされます。_​

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

<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
]
```