sort

array

Sorts array elements in ascending order

Syntax

sort(array)

Parameters

array (array)

The array to sort

Returns

array

A new sorted array

Examples

Input:
[3, 1, 2] | sort
Output:
[1, 2, 3]
Input:
["banana", "apple", "cherry"] | sort
Output:
["apple", "banana", "cherry"]

The sort() function sorts array elements in ascending order. For numeric arrays, it sorts from smallest to largest. For string arrays, it sorts alphabetically.

Usage

Use sort() for simple ascending sorts. For more complex sorting needs, use sort_by() to sort by specific fields.