_.sortBy(arrData, "rhid");
This code sorts array but as the values of field "rhid" are strings the order is messed up. How can i sort as if "rhid" where int field.
Thanks
Lodash helps in working with arrays, collection, strings, objects, numbers etc. The _. sortBy() method creates an array of elements which is sorted in ascending order by the results of running each element in a collection through each iteratee.
Creates an array of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee. This method performs a stable sort, that is, it preserves the original sort order of equal elements.
sortBy() function is used to sort all the elements of the list in ascending order according to the function given to it as a parameter. Passing the array with a function which returns the number and it will sort the array in ascending order and return an array. The array can be both of numeric values and string values.
sortBy
can be used with a function instead of a property name.
_.sortBy(arrData, function (obj) {
return parseInt(obj.rhid, 10);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With