Function sortProps

Sorts the properties of an object alphabetically, ascending or descending. It does not mutate the original object.

REMEMBER: In theory, JS engines do not guarantee the order of object properties. In practice most of the popular engines do.

sortProps({ b: 2, a: 1, z: 26 }) // { a: 1, b: 2, z: 26 }
  • Type Parameters

    • T extends Record<string, unknown>

    Parameters

    • object: T

      source object

    • asc: boolean = true

      sort ascending?

    Returns T