Sorting Arrays Of Objects With Lodash
The lodash
library comes with a couple functions for sorting collections of objects -- sortBy
and orderBy
.
Consider the following collection of pokemon:
This collection can be sorted in ascending order by the value of a key in the object using sortBy
.
If you want to control whether the sorting is in ascending or descending order, use orderBy
.
You can also do sorting with primary and secondary keys by including two values in the key sort array.
And if you want to indpendently control ascending/descending for these as well, you can.
Check out the live example to see it in action.
Last updated