Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sorted-object-entries

mgenware5MIT2.0.0TypeScript support: included

Sorted Object.entries in ascending or descending order.

object

readme

sorted-object-entries

Build Status npm version Node.js Version

Sorted Object.entries in ascending or descending order.

Installation

npm i sorted-object-entries

Usage

import sortedObjEntries from 'sorted-object-entries';

const obj = {
  liu: 1,
  zhang: 2,
  wu: 3,
  li: 4,
  zhao: 5,
  qian: 6,
  ao: 7,
  xue: 8,
  bo: 9,
};

sortedObjEntries(obj);
/* [
    ['ao', 7],
    ['bo', 9],
    ['li', 4],
    ['liu', 1],
    ['qian', 6],
    ['wu', 3],
    ['xue', 8],
    ['zhang', 2],
    ['zhao', 5],
  ]
*/

sortedObjEntries(obj, { desc: true });
/* [
    ['zhao', 5],
    ['zhang', 2],
    ['xue', 8],
    ['wu', 3],
    ['qian', 6],
    ['liu', 1],
    ['li', 4],
    ['bo', 9],
    ['ao', 7],
  ]
*/