Skip to content

sort

按数值属性对对象列表进行排序

131 bytes
since v12.1.0

使用方法

给定一个对象数组,返回一个新数组,按 get 函数中指定的数值属性排序。第三个可选参数允许您按降序排序,而不是默认的升序排序。

此函数仅支持数值排序。对于字母排序,请参见 alphabetical 函数。

import * as _ from "radashi";
const fish = [
{
name: "Marlin",
weight: 105,
},
{
name: "Bass",
weight: 8,
},
{
name: "Trout",
weight: 13,
},
];
_.sort(fish, (f) => f.weight); // => [bass, trout, marlin]
_.sort(fish, (f) => f.weight, true); // => [marlin, trout, bass]