Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

jaychsu/sort-object-list

Open more actions menu

Repository files navigation

sort-object-list

GitHub release npm Travis Maintenance license

To import component

Use any of the ways below to import

  • import sortObjectList from 'sort-object-list'
  • var sortObjectList = require('sort-object-list/es5').default
  • <script type="text/javascript" src="@node_modules/sort-object-list/es5/index.js"></script>

Usage

To sort an array of plain object

import sortObjectList from 'sort-object-list'

sortObjectList(
  [ 'B', 2, null, 1, undefined ],
  { sortBy: 'key' }
)
// [ 'B', 2, null, 1, undefined ]

sortObjectList(
  [ { key: 2 }, { key: 1 }, { key: 100 }, { key: 0 } ],
  { sortBy: 'key', isDecreasing: true }
)
// [ { key: 100 }, { key: 2 }, { key: 1 }, { key: 0 } ]

sortObjectList(
  [ { key: 'Z' }, { key: 'G' }, { key: 'B' }, { key: 'A' } ],
  { sortBy: 'key' }
)
// [ { key: 'A' }, { key: 'B' }, { key: 'G' }, { key: 'Z' } ]

sortObjectList(
  [
    { key: { something: 3 } },
    { key: { something: 1 } },
    { key: { something: 4 } },
    { key: { something: 0 } },
  ],
  { sortBy(object) { return object.key.something } }
)
// [
//   { key: { something: 0 } },
//   { key: { something: 1 } },
//   { key: { something: 3 } },
//   { key: { something: 4 } },
// ]

To sort children in react-native

import { Sorter } from 'sort-object-list/react-native'

<Sorter style={{...}}>
    <Text order={3}>B</Text>
    <Text order={0}>A</Text>
    <Text>C</Text>
</Sorter>

About

To sort an array of object by certain property.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.