Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-sort

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-sort

Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3M
increased by3.61%
Maintainers
2
Weekly downloads
 
Created

What is array-sort?

The array-sort npm package is a small, fast, and dependency-free library for sorting arrays of objects based on one or more properties. It allows for complex sorting mechanisms including sorting by nested properties, custom comparator functions, and multiple criteria.

What are array-sort's main functionalities?

Simple sorting

Sorts an array of objects by a single property. In this example, it sorts the array of users by their names in ascending order.

const sort = require('array-sort');
const users = [{ name: 'John' }, { name: 'Amy' }];
sort(users, 'name');

Descending order sorting

Sorts an array of objects by a property in descending order. Here, users are sorted by age in descending order using the '-' prefix.

const sort = require('array-sort');
const users = [{ age: 30 }, { age: 24 }];
sort(users, '-age');

Multiple criteria sorting

Sorts an array of objects by multiple properties. This example sorts users first by name and then by age in ascending order.

const sort = require('array-sort');
const users = [{ name: 'John', age: 25 }, { name: 'Amy', age: 22 }];
sort(users, ['name', 'age']);

Custom comparator function

Allows for custom sorting logic using a comparator function. This example sorts users by name using a locale-aware comparison.

const sort = require('array-sort');
const users = [{ name: 'John' }, { name: 'Amy' }];
sort(users, (a, b) => a.name.localeCompare(b.name));

Other packages similar to array-sort

Keywords

FAQs

Package last updated on 06 Dec 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc