The .orderBy() function can be used to sort fields in ascending and descending order.

📘

This type of sort will always do a string based sort. To do a number based sort you can use the Array(Object) option described next.

String Parameters

The .orderBy() function requires at least one parameter. Each parameter is the name of the field to perform an ascending sort on. You can perform a descending sort using the Array(Object) parameter described next.

orderBy( string, string , string, ...)
orderBy(field: string, ...fields: string[]): jinqJs;

Array Of Objects Paremeter

The .orderBy() function can except a single parameter of an array of objects. The field property can take a positional number to sort on. This is helpful when sorting on key value collections or plain arrays. Each orderBy object must be in the following format:
{
field: ‘Field’, <= (Optional, The string name or field position of the field to sort on)
sort: ‘asc|desc’ <= (Optional)
}

Note, if a field has a positional value then all fields must use a positional value too.

orderBy( Array( Object, Object, Object, … ) )
interface orderByParameter {
  field?: number | string;
  sort?: string;
}

orderBy(orderByParams: orderByParameter[]): jinqJs;
var result = new jinqJs()
                 .from([1,6,3,5,4,2])
                 .orderBy([{sort: 'desc'}])
                 .select();

/* result:  [6,5,4,3,2,1] */
var result = new jinqJs()
                 .from([{"john" : 28},{ "bob": 34},{ "joe" : 4}])
                 .orderBy([{field: 0}])
                 .select([{field: 0, text: 'Ages'}]);

/* result:  [{Ages: 4}, {Ages: 28}, {Ages: 34}] */