Options
All
  • Public
  • Public/Protected
  • All
Menu

Module sortBy

Index

References

Functions Collection

References

Renames and re-exports __type

Collection Functions

  • sortBy<T>(collection: ArrayLike<T>, iteratees?: ArrayAble<KeyIteratee | ArrayIteratee<T, any>>): T[]
  • Creates an array of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee. This method performs a stable sort, that is, it preserves the original sort order of equal elements. The iteratees are invoked with one argument: (value).

    since

    5.11.0

    example
    var users = [
    { 'user': 'fred', 'age': 48 },
    { 'user': 'barney', 'age': 36 },
    { 'user': 'fred', 'age': 40 },
    { 'user': 'barney', 'age': 34 }
    ];

    sortBy(users, [function(o) { return o.user; }]);
    // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

    sortBy(users, ['user', 'age']);
    // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]

    Type parameters

    • T

    Parameters

    • collection: ArrayLike<T>

      The collection to iterate over.

    • Optional iteratees: ArrayAble<KeyIteratee | ArrayIteratee<T, any>>

      The iteratees to sort by.

    Returns T[]

    Returns the new sorted array.