---
schema_version: "1"
id: ba26dba6f41e022f9f0d60de05e158560c75ae44dd22abb5df479f86fff414c3
title: maxBy
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.4/dw-core-functions-maxby.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.4/dw-core-functions-maxby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b10c61ee0f7ff15a8f990074dddab4e2cea1d1ce7a05a8e1c598ddd0c4ced69d
description: MuleSoft Documentation Site
release: "2.4"
latest: false
---
# maxBy

## [](#maxby1)maxBy<T>(@StreamCapable array: Array<T>, criteria: (item: T) -> Comparable): T | Null

配列を反復処理し、配列から ​`Comparable`​ 要素の最大値を返します。

項目のデータ型は同じである必要があります。同じでない場合、​`maxBy`​ はエラーをスローし、配列が空の場合は、関数は ​`null`​ を返します。

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

<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>criteria</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">配列から ​<code>Number</code>​ (数値)、​<code>Boolean</code>​ (ブール)、​<code>DateTime</code>​ (日時)、​<code>LocalDateTime</code>​ (ローカル日時)、​<code>Date</code>​ (日付)、​<code>LocalTime</code>​ (ローカル時刻)、​<code>Time</code>​ (時刻)、または ​<code>TimeZone</code>​ (タイムゾーン) データ型の項目を選択するための式。​<code>$</code>​ で参照できます。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、配列のオブジェクト (キー-値ペア) 内の最大数値を返します。​`item.a`​ を使用してオブジェクトの値を選択しています。​`[ { "a" : 1 }, { "a" : 3 }, { "a" : 2 } ] maxBy $.a`​ のように、匿名パラメーターを使用して同じ式を記述することもできます。

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

```DataWeave
%dw 2.0
output  application/json
---
[ { "a" : 1 }, { "a" : 3 }, { "a" : 2 } ] maxBy ((item) -> item.a)
```

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

```JSON
{ "a" : 3 }
```

### [](#例-2)例

次の例では、変数 ​`myDateTime1`​ および ​`myDateTime2`​ で定義された入力から最新の ​`DateTime`​ (日時)、​`Date`​ (日付)、および ​`Time`​ (時刻) を取得します。また、この関数は空の配列に対して null を返すことも示しています。

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

```DataWeave
%dw 2.0
var myDateTime1 = "2017-10-01T22:57:59-03:00"
var myDateTime2 = "2018-10-01T23:57:59-03:00"
output application/json
---
{
  myMaxBy: {
    byDateTime: [ myDateTime1, myDateTime2 ] maxBy ((item) -> item),
    byDate: [ myDateTime1 as Date, myDateTime2 as Date ] maxBy ((item) -> item),
    byTime: [ myDateTime1 as Time, myDateTime2 as Time ] maxBy ((item) -> item),
    emptyArray: [] maxBy ((item) -> item)
  }
}
```

#### [](#出力-2)出力

```JSON
{
  "myMaxBy": {
    "byDateTime": "2018-10-01T23:57:59-03:00",
    "byDate": "2018-10-01",
    "byTime": "23:57:59-03:00",
    "emptyArray": null
  }
}
```