sort

Task purpose

The sort task sorts the elements of a given array and returns the sorted array. The default sort order is ascending (A to Z, 0 to 9). This task modifies the position of elements in the original array.

Potential use case

Use sort to arrange a list of names in alphabetical order, sort a collection of dates numerically, or order any array of numbers, strings, or objects.

Properties

IncomingTypeDescription
arrArrayRequired. The array to sort.
keyStringOptional. For arrays of objects, the property key to sort by.
limitNumberOptional. The maximum number of records to return.
reverseBooleanRequired. If true, sorts in descending order. Default: false (ascending).
OutgoingTypeDescription
responseArrayThe sorted array.

Examples

Example 1

In this example:

  • arr is statically set to [{"name":"cat"},{"name":"dog"},{"name":"hamster"},{"name":"ant"},{"name":"Lion"}]. Note that "Lion" begins with an uppercase letter.
  • key is name and limit is 4.
  • reverse is false (default — ascending order).
sort example 1 — configuration

The result is ascending order, with "Lion" listed first because uppercase letters sort before lowercase letters.

sort example 1 — output

Example 2

In this example:

  • arr is statically set to [{"car":"Audi"},{"car":"Volvo"},{"car":"Honda"},{"car":"BMW"}]. All names begin with uppercase letters.
  • key is car and limit is left blank.
  • reverse is false (default — ascending order).
sort example 2 — configuration

The result is alphabetical (ascending) order.

sort example 2 — output

Example 3

In this example:

  • arr is statically set to ["ant","bee","Cat","dog","Elephant"]. The values mix lowercase and uppercase.
  • key and limit are left blank.
  • reverse is true (descending order).
sort example 3 — configuration

The result is descending order, with all lowercase values in reverse alphabetical order followed by the uppercase values.

sort example 3 — output