Home > widget-integration > FilterHelper > sortByKey

FilterHelper.sortByKey() method

Sorts data by a specified key Works with both arrays and objects

Signature:

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

Parameters

Parameter

Type

Description

data

T[] | Record<string, T>

Array or object to sort

key

string

Key to sort by

order

"asc" | "desc"

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

Returns:

T[] | Record<string, T> | undefined

Sorted array or object