
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
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.
The npm package lodash.orderby receives a total of 418,477 weekly downloads. As such, lodash.orderby popularity was classified as popular.
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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.