
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
lodash.orderby
Advanced tools
The lodash.orderby package is a utility library that provides a method for sorting collections (arrays or objects) based on multiple criteria. It is part of the larger Lodash library, which is known for its performance and ease of use.
Sort by Single Property
This feature allows you to sort an array of objects by a single property. In this example, the users array is sorted by the 'user' property in ascending order.
const _ = require('lodash.orderby');
const users = [
{ 'user': 'fred', 'age': 48 },
{ 'user': 'barney', 'age': 34 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 36 }
];
const sortedUsers = _.orderBy(users, ['user'], ['asc']);
console.log(sortedUsers);
Sort by Multiple Properties
This feature allows you to sort an array of objects by multiple properties. In this example, the users array is first sorted by the 'user' property in ascending order, and then by the 'age' property in descending order.
const _ = require('lodash.orderby');
const users = [
{ 'user': 'fred', 'age': 48 },
{ 'user': 'barney', 'age': 34 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 36 }
];
const sortedUsers = _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
console.log(sortedUsers);
Sort by Nested Properties
This feature allows you to sort an array of objects by nested properties. In this example, the users array is sorted by the 'details.age' property in ascending order.
const _ = require('lodash.orderby');
const users = [
{ 'user': 'fred', 'details': { 'age': 48 } },
{ 'user': 'barney', 'details': { 'age': 34 } },
{ 'user': 'fred', 'details': { 'age': 40 } },
{ 'user': 'barney', 'details': { 'age': 36 } }
];
const sortedUsers = _.orderBy(users, ['details.age'], ['asc']);
console.log(sortedUsers);
The sort-array package provides a simple and flexible way to sort arrays of objects by multiple properties. It is similar to lodash.orderby but is a smaller, more focused library specifically for sorting arrays.
The array-sort package allows you to sort arrays of objects by multiple properties. It is similar to lodash.orderby but offers a more concise syntax and is focused solely on sorting functionality.
The sort-by package provides a utility for sorting arrays of objects by multiple properties. It is similar to lodash.orderby but is a smaller, more lightweight library with a focus on simplicity and ease of use.
The lodash method _.orderBy
exported as a Node.js module.
Using npm:
$ {sudo -H} npm i -g npm
$ npm i --save lodash.orderby
In Node.js:
var orderBy = require('lodash.orderby');
See the documentation or package source for more details.
FAQs
The lodash method `_.orderBy` exported as a module.
We found that lodash.orderby demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.