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

## [](#countby1)countBy(Array<T>, (T) -> Boolean): Number

マッチング関数が各要素の値に適用されるときに ​`true`​ を返す配列内の要素を数えます。

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

<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>matchingFunction</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">入力配列の要素に適用される関数。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、関数 ​`(($ mod 2) == 0)`​ に値が適用されたときに ​`true`​ を返す入力配列 (\[1, 2, 3, 4\]) 内の要素数を数えます。この場合、​`2 mod 2 == 0`​、​`4 mod 2 == 0`​ であるため、要素の ​_2 つ_​の値 (​`2`​ と ​`4`​ の両方) が一致します。その結果、​`countBy`​ 関数は ​`2`​ を返します。​`mod`​ は、オペランドのモジュールを返します。

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

```DataWeave
 %dw 2.0
 import * from dw::core::Arrays
 output application/json
 ---
{ "countBy" : [1, 2, 3, 4] countBy (($ mod 2) == 0) }
```

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

```JSON
{ "countBy": 2 }
```