---
schema_version: "1"
id: 2c3dae67a52a963c1767af4f0d7f2862ec8e58953d6792093298991da841a9da
title: orderBy
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.3/dw-core-functions-orderby.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.3/dw-core-functions-orderby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 45c75942afc818b6f9ddd8c5220c3f764e91479d5b5c29c8d55036e091f8b348
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
# orderBy

## [](#orderby1)orderBy(O, (value: V, key: K) -> R): O

入力の要素を、その入力の選択された要素で動作する条件を使用して並び替えます。

このバージョンの ​`orderBy`​ は、入力としてオブジェクトを使用します。その他のバージョンは、入力配列で動作するか、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>object</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">関数の結果は、オブジェクトを並び替える条件として使用されます。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、入力配列内の各オブジェクトの値をアルファベット順に並べます。​`orderBy($.letter)`​ は ​`orderBy($[0])`​ と同じ結果になります。

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

```DataWeave
%dw 2.0
output application/json
---
[{ letter: "e" }, { letter: "d" }] orderBy($.letter)
```

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

```JSON
[
  {
    "letter": "d"
  },
  {
    "letter": "e"
  }
]
```

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

`orderBy`​ 関数には、昇順ではなく降順で並び替えるオプションはありません。この場合は、たとえば ​`-`​ を使用して、結果の配列の順序を単に反転することができます。

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

```DataWeave
%dw 2.0
output application/json
---
orderDescending: ([3,8,1] orderBy -$)
```

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

```JSON
{ "orderDescending": [8,3,1] }
```

## [](#orderby2)orderBy(Array<T>, (item: T, index: Number) -> R): Array<T>

指定された条件を使用して配列を並び替えます。

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

<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">関数の結果は、リストを並び替える条件として使用されます。単純な値 (文字列、数値など) を返す必要があります。</p></td>
</tr>
</tbody>
</table>

### [](#例-3)例

次の例では、数値に基づいて数値の配列を並び替えます。

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

```DataWeave
%dw 2.0
output application/json
---
[3,2,3] orderBy $
```

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

```JSON
[ 2, 3, 3 ]
```

### [](#例-4)例

次の例では、age (年齢) に基づいて人の配列を並び替えます。

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

```DataWeave
%dw 2.0
output application/json
---
[{name: "Santiago", age: 42},{name: "Leandro", age: 29}, {name: "Mariano", age: 35}] orderBy (person) -> person.age
```

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

```JSON
[
  {
    name: "Leandro",
    age: 29
  },
  {
    name: "Mariano",
    age: 35
  },
  {
    name: "Santiago",
    age: 42
  }
]
```

### [](#例-5)例

この例は、JSON 配列内のオブジェクトの順序を変更します。この式は、最初に ​`Type`​ キーの値をアルファベット順に並び替えてから、​`[-1 to 0]`​ に基づいて順序を逆にします。

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

```DataWeave
%dw 2.0
var myInput = [
    {
        "AccountNumber": "987999321",
        "NameOnAccount": "QA",
        "Type": "AAAA",
        "CDetail": {
            "Status": "Open"
        }
    },
    {
        "AccountNumber": "12399978",
        "NameOnAccount": "QA",
        "Type": "BBBB",
        "CDetail": {}
    },
    {
        "AccountNumber": "32199974",
        "NameOnAccount": "QA",
        "Type": "CCCC",
        "CDetail": {}
    }
]
output application/json
---
(myInput orderBy $.Type)[-1 to 0]
```

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

```JSON
[
  {
    "AccountNumber": "32199974",
    "NameOnAccount": "QA",
    "Type": "CCCC",
    "CDetail": {

    }
  },
  {
    "AccountNumber": "12399978",
    "NameOnAccount": "QA",
    "Type": "BBBB",
    "CDetail": {

    }
  },
  {
    "AccountNumber": "987999321",
    "NameOnAccount": "QA",
    "Type": "AAAA",
    "CDetail": {
      "Status": "Open"
    }
  }
]
```

## [](#orderby3)orderBy(Null, (item: Nothing, index: Nothing) -> Null): Null

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