I\'d like to know why lodash doesn\'t sort array of dates in string format as compared with plain javascript sort()
. Is it expected behavior or a bug?
If you are trying to use lodash to sort dates in ascending or descending order for your array of objects, you should use _.orderBy
instead of _.sortBy
https://lodash.com/docs/4.17.15#orderBy, this method allows specifying sort orders either by 'asc'
or'desc'
An example would be:
const sortedArray = _(myArray.orderBy([
function(object) {
return new Date(object.date);
}],["desc"])