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

## [](#countby1)countBy<T>(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 で導入されました。_