• Sorts the elements of a sequence in ascending order.

    Type Parameters

    • TSource
    • TKey

    Parameters

    • src: Iterable<TSource>

      The source iterable.

    • keySelector: (item: TSource) => TKey

      A function to extract the key for each element.

    Returns IOrderedEnumerable<TSource>

    An IOrderedEnumerable whose elements are sorted according to a key.

    const items = [{ id: 1 }, { id: 3 }, { id: 2 }];
    const ordered = orderBy(items, x => x.id).toArray(); // Will be [{ id: 1 }, { id: 2 }, { id: 3 }]

    TSource The type of the source iterable.

    TKey The type of the key returned by keySelector.

  • Sorts the elements of a sequence in ascending order.

    Type Parameters

    • TSource
    • TKey

    Parameters

    • src: Iterable<TSource>

      The source iterable.

    • keySelector: (item: TSource) => TKey

      A function to extract the key for each element.

    • comparer: Comparer<TKey>

      An Comparer to compare keys.

    Returns IOrderedEnumerable<TSource>

    An IOrderedEnumerable whose elements are sorted according to a key.

    const items = [{ id: 1 }, { id: 3 }, { id: 2 }];
    const ordered = orderBy(items, x => x.id).toArray(); // Will be [{ id: 1 }, { id: 2 }, { id: 3 }]

    TSource The type of the source iterable.

    TKey The type of the key returned by keySelector.