Home > widget-integration > FilterHelper > sortArrayByKey

FilterHelper.sortArrayByKey() method

Sorts an array by a specified key Handles numeric (for numbers) and string values with lexical comparison (for strings, including numeric-looking strings) Mixed number/string: attempts numeric if string is numeric, else lexical

Signature:

sortArrayByKey<T extends Record<string, any>>(array: T[], key: string, order?: "asc" | "desc"): T[];

Parameters

Parameter

Type

Description

array

T[]

Array to sort

key

string

Key to sort by

order

"asc" | "desc"

(Optional) Sort order ('asc' or 'desc')

Returns:

T[]

Sorted array