@tremendous/help
    Preparing search index...

    Function sortBy

    • Sorts an array by the values extracted by the iteratee function.

      This function takes an array and a function that extracts a value from each element, and returns a new array sorted based on the extracted values.

      Type Parameters

      • ArrayElement = unknown

        The type of the elements in the array.

      • ExtractedValue = ArrayElement

        The type of the values extracted from the elements.

      Parameters

      Returns ArrayElement[]

      • The sorted array.
      const array = [
      { name: 'John', age: 25 },
      { name: 'Jane', age: 22 },
      { name: 'Jack', age: 27 }
      ];
      const sorted = sortBy(array, x => x.age);
      // sorted will be [
      // { name: 'Jane', age: 22 },
      // { name: 'John', age: 25 },
      // { name: 'Jack', age: 27 }
      // ]