Skip to content
On this page

Sort by

The sortby function sorts the contents of a range or array based on the values in a corresponding range or array.

This functions is ready to use without importing.

Overview

typescript
declare global {
  interface Array<T> {
    sortBy(key: string | number): Array<T>;
  }
}

Usage

typescript
const myArray = [
  {
    value: 'd',
  },
  {
    value: 'g',
  },
  {
    value: 'z',
  },
  {
    value: 'a',
  },
];

console.log(myArray.sortBy('value'));

/** output:
 
 [
  {
    value: 'a'
  },
  {
    value: 'd'
  },
  {
    value: 'g'
  },
  {
    value: 'z'
  }
]

 */

Clinux UI - Released under the MIT License.