---
category: [Administration & Integrations, Platform and Product Extensions, Platform and Product Extensions/Integration, Administration & Integrations/Custom Integrations & Apps, Platform and Product Extensions/Workday Extend]
keyword: [Extend, PMD Scripting, Scripts]
nav: wcp_docs
parent_url: /wcp_docs/
title: sort (closure)
layout: subsection
---

## <a id="section_m3p_myb_5db"></a>Description

Calls the specified function on every element of the list, then sorts the elements according to the results of the specified function. The `sort` function returns the new sorted list.

## <a id="section_cyq_j1m_zsb"></a>Return Type

`List`

## <a id="section_dz5_pwg_5db"></a>Instance Method Syntax

```
thisList.sort(closure)
```

<table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td>closure</td><td>The function to call on each element. <p>Within a closure, you can't redefine the variables that are declared outside the closure.</p></td></tr></tbody></table><br/>

<b>Example</b>

`['22', '1', '333'].sort(x => {x.length()})`

Returns `['1', '22', '333']`

## <a id="section_dz5_pwg"></a>Namespace Function Syntax

`list:sort(list, closure)`

<table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td>list</td><td>The input List.</td></tr><tr><td>closure</td><td>The function to call on each element.</td></tr></tbody></table><br/>

