---
schema_version: "1"
id: 6a133c5aa0533a5eb2f371b421c4d0c056017b62f1c89404130dafedf1f47e19
title: "Handlebars Helper Function: sort"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/handlebars/reference/utility/mcn-handlebars-reference-utility-sort.md
canonical_url: https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-utility-references/mcn-handlebars-reference-utility-sort.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 92d8ea3b55a0467cbc2bf634ca914a4c225d9c4d712d44d6272f32c7baefbf07
products:
  - Handlebars for Marketing Cloud Next
  - Marketing Cloud
---
# Handlebars Helper Function: sort

Sorts a list of objects by a specified field, order, and type. Supports sorting as string, number, date, or boolean.

## Availability

This helper is available in the Winter ’26 release of Marketing Cloud Next.

## Syntax

```handlebars
{{sort list fieldName sortOrder sortAs}}
```

## Parameters

| Parameter   | Type   | Description                                                                                                                        |
| ----------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| `list`      | Array  | Required. The list of objects to sort.                                                                                             |
| `fieldName` | String | Required. The field to sort by. Must exist in all objects.                                                                         |
| `sortOrder` | String | Required. The sort order. Valid values are `"asc"` (ascending order) and `"desc"` (descending order).                              |
| `sortAs`    | String | Required. The type to sort as. Valid values: <ul><li>`"string"`</li><li>`"number"`</li><li>`"date"`</li><li>`"boolean"`</li></ul>. |

## Return Value

The function returns a new list sorted by the specified field, order, and type. Objects with missing fields or invalid values for the specified type are excluded from the result. If a parameter is missing or invalid, the function throws an exception.

### Usage Examples

This example shows how to use the `sort` function to sort a list of objects by the `age` field in ascending order.

```javascript
myList = [{"age": 24}, {"age": 27}, {"age": 21}];

{{sort myList "age" "asc" "number"}}
```

The function returns `[{"age": 21}, {"age": 24}, {"age": 27}]`.

### String Sorting

When the field is a string, the function sorts the strings in alphabetical order, as shown in this example.

```javascript
myList = [{"name": "John"}, {"name": "Alice"}, {"name": "Bob"}];

{{sort myList "name" "asc" "string"}}
```

The function returns `[{"name": "Alice"}, {"name": "Bob"}, {"name": "John"}]`.

### Boolean Sorting

When the field is a boolean, the function sorts the booleans with `false` before `true`, as shown in this example.

```javascript
myList = [{"isActive": false}, {"isActive": true}];

{{sort myList "isActive" "asc" "boolean"}}
```

The function returns `[{"isActive": false}, {"isActive: true}]`.

### Nested Helpers

You can combine the `sort` function with the `filter` function to filter a list by one field, and then sort the resulting list by another field.

This example shows how to use the `sort` function with the `filter` function to sort a list of objects by the `createdAt` field in descending order, only including objects where the value of the `total` field is greater than 100.

```javascript
myList = [
  {"orderId": "o1", "createdAt": "2024-01-10", "total": 100},
  {"orderId": "o2", "createdAt": "2024-01-11", "total": 120},
  {"orderId": "o3", "createdAt": "2024-01-12", "total": 150}
];

{{sort (filter myList "total" ">" 100 "number") "createdAt" "desc" "date"}}
```

The function returns this list:

```json
[
  { "orderId": "o3", "createdAt": "2024-01-12", "total": 150 },
  { "orderId": "o2", "createdAt": "2024-01-11", "total": 120 }
]
```
