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.
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]]
Name | Type | Attribute | Description |
---|---|---|---|
collection | The collection to iterate over. | ||
iteratees | The iteratees to sort by. | ||
orders | The sort orders of `iteratees`. |
{ "comment": "/**\r\n * This method is like `sortBy` except that it allows specifying the sort\r\n * orders of the iteratees to sort by. If `orders` is unspecified, all values\r\n * are sorted in ascending order. Otherwise, specify an order of \"desc\" for\r\n * descending or \"asc\" for ascending sort order of corresponding values.\r\n *\r\n * @since 4.0.0\r\n * @category Collection\r\n * @param {Array|Object} collection The collection to iterate over.\r\n * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[identity]]\r\n * The iteratees to sort by.\r\n * @param {string[]} [orders] The sort orders of `iteratees`.\r\n * @returns {Array} Returns the new sorted array.\r\n * @see reverse\r\n * @example\r\n *\r\n * const users = [\r\n * { 'user': 'fred', 'age': 48 },\r\n * { 'user': 'barney', 'age': 34 },\r\n * { 'user': 'fred', 'age': 40 },\r\n * { 'user': 'barney', 'age': 36 }\r\n * ]\r\n *\r\n * // Sort by `user` in ascending order and by `age` in descending order.\r\n * orderBy(users, ['user', 'age'], ['asc', 'desc'])\r\n * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]\r\n */", "meta": { "range": [ 1134, 1466 ], "filename": "orderBy.js", "lineno": 30, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100006527", "name": "orderBy", "type": "FunctionDeclaration", "paramnames": [ "collection", "iteratees", "orders" ] }, "vars": { "iteratees": "orderBy~iteratees", "orders": "orderBy~orders" } }, "description": "This method is like `sortBy` except that it allows specifying the sort\rorders of the iteratees to sort by. If `orders` is unspecified, all values\rare sorted in ascending order. Otherwise, specify an order of \"desc\" for\rdescending or \"asc\" for ascending sort order of corresponding values.", "since": "4.0.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Collection", "value": "Collection" } ], "params": [ { "type": { "names": [ "Array", "Object" ] }, "description": "The collection to iterate over.", "name": "collection" }, { "type": { "names": [ "Array.", "Array. ", "Array.