My question is kinda linked to this one, but one step more complex : lodash orderby with null and real values not ordering correctly
Basically I have something like this :
let objs = [{x: {y: 1, z: 2}, a: 3}, {x: null, a: 4}];
let sortKeys = ['x.y', 'a']; //this is dynamic, can have multiple fields
The user can pass different values for sorting, like x.y
or just a
and sometimes x
is null. So when I use the normal _.orderBy(objs, sortKeys, ['desc'])
it shows null values first.
How can I do so that the null values appears last?