lodash orderby with null and real values not ordering correctly lodash orderby with null and real values not ordering correctly typescript typescript

lodash orderby with null and real values not ordering correctly


The _.orderBy() function's iteratees can use a method instead of a string. Check the value, and if it's null return an empty string.

const myArray = [{ propertyName: 'cats' }, { propertyName: null }, { propertyName: 'dogs' }, { propertyName: 'rats' }, { propertyName: null }];const result = _.orderBy(myArray, ({ propertyName }) => propertyName || '', ['desc']);console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.min.js"></script>