Options
All
  • Public
  • Public/Protected
  • All
Menu

Module orderBy

Index

References

Functions Collection

References

Renames and re-exports orderBy

Collection Functions

  • orderBy<T, T2>(collection: Collection<T>, iteratees: ArrayAble<KeyIteratee | CollectionIteratee<T, T2>>, orders: ArrayAble<Order<T2>>, guard?: any): T[]
  • This method is like sortBy except that it allows specifying the sort orders of the iteratees to sort by. If orders is unspecified, all values are sorted in ascending order. Otherwise, specify an order of "desc" for descending or "asc" for ascending sort order of corresponding values. You may also specify a compare function for an order.

    since

    5.10.0

    see

    [[reverse]]

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

    // Sort by `user` in ascending order and by `age` in descending order.
    orderBy(users, ['user', 'age'], ['asc', 'desc'])
    // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

    // Sort by `user` then by `age` using custom compare functions for each
    orderBy(users, ['user', 'age'], [
    (a, b) => a.localeCompare(b, 'de', { sensitivity: 'base' }),
    (a, b) => a - b,
    ])

    Type parameters

    • T

    • T2

    Parameters

    • collection: Collection<T>

      The collection to iterate over.

    • iteratees: ArrayAble<KeyIteratee | CollectionIteratee<T, T2>>

      The iteratees to sort by.

    • orders: ArrayAble<Order<T2>>

      The sort orders of iteratees.

    • Optional guard: any

    Returns T[]

    Array Returns the new sorted array.