@rogerpence/rp-utils
    Preparing search index...

    Function sortObjArray

    • Sorts an array of objects by one or more properties with configurable sort order.

      Type Parameters

      • T extends Record<string, any>

        The type of objects in the array

      Parameters

      • arr: T[]

        The array to sort

      • props: (keyof T)[]

        Array of property names to sort by (in priority order)

      • Optionalorders: ("asc" | "desc")[] = []

        Optional sort order for each property ('asc' or 'desc'). Defaults to 'asc'.

      Returns T[]

      The sorted array

      Sort by count descending, then tag ascending

      const sortedObjs = sortObjArray(tags, ['count', 'tag'], ['desc', 'asc']);
      

      Sort by count descending (default order for other props is asc)

      const sortedObjs = sortObjArray(tags, ['count', 'tag'], ['desc']);