Sometimes, we want to use Lodash to sort array of object by value with JavaScript
In this article, we’ll look at how to use Lodash to sort array of object by value with JavaScript.
How to use Lodash to sort array of object by value with JavaScript?
To use Lodash to sort array of object by value with JavaScript, we use the orderBy
method.
For instance, we write
const sortedChars = _.orderBy(chars, ["name"], ["asc"]);
to call orderBy
to sort the chars
array by the name
property of each object in chars
.
We use ['asc']
to specify that we sort by ascending order.
Conclusion
To use Lodash to sort array of object by value with JavaScript, we use the orderBy
method.