Skip to content

sort

The sort() function sorts an array of strings in ascending (ASC) or descending (DSC) order and returns a new array.

Interactive example

Syntax

Classic signature

typescript
function sort<
  GenericArray extends readonly string[],
>(
  array: GenericArray,
  type: SortType,
): string[]

Curried signature

typescript
function sort<
  GenericArray extends readonly string[],
>(
  type: SortType,
): (array: GenericArray) => string[]

Parameters

  • array: Array of strings to sort.
  • type: Sort order, "ASC" (ascending) or "DSC" (descending).

Return value

A new array of sorted strings. The original array remains unchanged.

See also

  • concat - Concatenates multiple strings
  • split - Splits a string into an array

Released under the MIT license.