Skip to content

SortByField

cartographer


cartographer / sortByField

sortByField(items, fieldKey, descending, fieldType): CatalogItem[]

Defined in: queries/queryFunctions.ts:493

Sort items by a field with type-aware comparison.

Handles null values gracefully (sorts to end). Supports string, number, and date field types.

CatalogItem[]

Array of items to sort

string

Field key to sort by

boolean = false

Sort order (default: false for ascending)

string = 'string'

Type for comparison: ‘string’, ‘number’, or ‘date’ (default: ‘string’)

CatalogItem[]

  • New sorted array (original array not mutated)
const byYear = sortByField(items, 'year', true, 'number'); // Descending by year