toolish - v0.2.5
    Preparing search index...

    Function sortArrayBy

    • Sorts an array in place by one or more specific keys. If two elements compare equally with a given key, the next one is tried, and so on. The same order is applied for all keys.

      If you need to preserve the original array, make a copy first with e.g. Array.slice.

      Values of differing types are sorted in groups in this order: nullish, booleans, numbers (including numeric strings), strings, symbols, objects, functions. Objects are sorted by Object.valueOf if that returns a primitive, their JSON representation otherwise (note arrays fall into this category as well). Functions are sorted by Function.toString. All strings are sorted case-insensitive (including string obtained from objects or functions)

      NOTE this is unlike Array.sort, which sorts by string representation and moves all undefined elements to the end.

      Type Parameters

      • T

      Parameters

      • array: T[]
      • key: MaybeArray<keyof T>

        name of an element property

      • Optionalorder: number

        any positive number for ascending (default); negative for descending (0 retains original order, i.e. the sort has no effect)

      Returns T[]

      the given array

    • Like sortArrayBy:STRING_KEYS_SAME_ORDER, but allows passing a specific order for each key. Ascending order is assumed for any key without corresponding order.

      Type Parameters

      • T

      Parameters

      • array: T[]
      • keys: (keyof T)[]
      • orders: number[]

      Returns T[]

    • Like sortArrayBy:STRING_KEYS_SAME_ORDER, but allows passing one or more functions that return the sort values of a given element.

      Type Parameters

      • T

      Parameters

      Returns T[]

    • Like sortArrayBy:FUNCTION_KEYS_SAME_ORDER, but allows passing a specific order for each key. Ascending order is assumed for any key without corresponding order.

      Type Parameters

      • T

      Parameters

      Returns T[]