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

sort-object

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-object

Sort the keys in an object.

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
517K
decreased by-7.25%
Maintainers
2
Weekly downloads
 
Created

What is sort-object?

The sort-object npm package is used to sort the keys of an object in JavaScript. It provides a simple and efficient way to order the properties of an object based on their keys, which can be useful for various purposes such as ensuring consistent key order for JSON serialization, improving readability, or preparing data for comparison.

What are sort-object's main functionalities?

Sort object keys alphabetically

This feature sorts the keys of an object in alphabetical order. The code sample demonstrates how to use the sort-object package to sort the keys of an object alphabetically.

const sortObject = require('sort-object');
const obj = { b: 2, a: 1, c: 3 };
const sortedObj = sortObject(obj);
console.log(sortedObj); // { a: 1, b: 2, c: 3 }

Sort object keys with a custom comparator

This feature allows sorting the keys of an object using a custom comparator function. The code sample demonstrates how to use a custom comparator to sort the keys in reverse alphabetical order.

const sortObject = require('sort-object');
const obj = { b: 2, a: 1, c: 3 };
const sortedObj = sortObject(obj, { sort: (a, b) => b.localeCompare(a) });
console.log(sortedObj); // { c: 3, b: 2, a: 1 }

Other packages similar to sort-object

Keywords

FAQs

Package last updated on 21 Aug 2014

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