• Sorts an array of objects by the specified object key/property or selected by function. In comparison to the native Array.sort arrays are not sorted in placed but a newly sorted array is returned. The original array order is not changed

    Type Parameters

    • T extends object

    • K extends string | number

    Parameters

    • iterable: Iterable<T> | readonly T[]

      Iterable object or readonly array

    • byField: keyof T | ((item) => K)

      Property selector function or name

    • order: "asc" | "desc" = 'asc'

      order by which to sort; defaults to 'asc' when undefined

    Returns T[]

    Copy of the iterable or array as array sorted by the specified field in desc or asc order