---
schema_version: "1"
id: ac0b02a0705f4f0edad67dd960d23811ad9a2456c256025b12296bae92b1171a
title: countBy
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.4/dw-arrays-functions-countby.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.4/dw-arrays-functions-countby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: d7a0afd57bea3bc9ca6a431519f9d64db8b060954b90c72a40c438e9932238b0
description: MuleSoft Documentation Site
release: "2.4"
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 で導入されました。_​