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

## [](#countby1)countBy<T>(@StreamCapable array: Array<T>, matchingFunction: (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 }
```

## [](#countby2)countBy(array: Null, matchingFunction: (Nothing) -> Any): Null

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

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