Reputation: 21452
here is my case I am trying to sort an array with two name and crop equal true I am using lodash sortBy method
https://lodash.com/docs/4.17.11#sortBy
it working just fine with sorting string but not working with boolean filed
here is my code
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"])
);
Upvotes: 1
Views: 81
Reputation: 10960
Use
_.orderBy(unsortedArray , ["name" ,"crop"], ["asc", "desc"]);
Upvotes: 1