Function sortObjectByKey

  • Sorts an array of objects based on a specified key in ascending or descending order.

    Type Parameters

    • T

    • K extends string | number | symbol

    Parameters

    • arr: T[] = []

      An array of objects to be sorted. Default value is an empty array.

    • key: K

      The key based on which the objects should be sorted.

    • order: number = 1

      The sorting order. Default value is 1 (ascending), but can be set to -1 for descending order.

    Returns T[]

    The sorted array of objects based on the specified key and order.

Generated using TypeDoc