这是我的情况,我正在尝试用两个名称对数组进行排序,并且crop等于true 我正在使用lodash sortBy方法
https://lodash.com/docs/4.17.11#sortBy
它可以很好地处理字符串,但不能处理布尔字段
这是我的代码
const unsortedArray = [
{ name: "mina", lastName: "a", crop: false },
{ name: "aaa", lastName: "fa", crop: true },
{ name: "mina", lastName: "a", crop: true }
];
console.log("un sorted array ", unsortedArray);
console.log(
" sorted array ",
_.sortBy(unsortedArray , ["name" ,"crop"])
);
答案 0 :(得分:1)
使用
_.orderBy(unsortedArray , ["name" ,"crop"], ["asc", "desc"]);