Sometimes, we want to do multi-column sortBy with lodash and JavaScript.
In this article, we’ll look at how to do multi-column sortBy with lodash and JavaScript.
How to do multi-column sortBy with lodash and JavaScript?
To do multi-column sortBy with lodash and JavaScript, we can use the orderBy
function.
For instance, we write
const data = _.orderBy(arr, ["type", "name"], ["asc", "desc"]);
to call orderBy
with the arr
array that we want to sort.
And we call it with 2 arrays that has the property we want to sort by and the direction.
Then the array with the sorted items is returned.
Conclusion
To do multi-column sortBy with lodash and JavaScript, we can use the orderBy
function.