3.0.0 โ€ข Published 4 years ago

sort-array-objects v3.0.0

Weekly downloads
39
License
MIT
Repository
github
Last release
4 years ago

sort-array-objects

Sort an array of objects by one or several properties, and return a new array.

Note: v3 has breaking changes ๐Ÿ”ฅ

Usage ๐Ÿ–ฅ

import sort from 'sort-array-objects';

const data = [
  { id: 1, a: 456, b: 635, c: 682 },
  { id: 2, a: 100, b: 99, c: 333 },
  { id: 3, a: 100, b: 238, c: 123 },
];

sort(data, ['a', 'b']);
// ==> [
// {"id":2,"a":100,"b":99,"c":333},
// {"id":3,"a":100,"b":238,"c":123},
// {"id":1,"a":456,"b":635,"c":682},
// ]

sort(data, ['a', 'b'], -1);
// ==> [
// {"id":1,"a":456,"b":635,"c":682},
// {"id":3,"a":100,"b":238,"c":123},
// {"id":2,"a":100,"b":99,"c":333},
// ]

Install ๐Ÿ”Œ

$ npm i -S sort-array-objects

License ๐Ÿงพ

MIT

3.0.0

4 years ago

2.0.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago