Here is a suggestion for using the orderBy function from lodash in a recommended way:
const data = _.orderBy(array_of_objects, ['type','name'], ['asc', 'desc']); - instead of keys
Is there a way to accomplish sorting based on deep values by passing key paths as string arrays like this ['type.id','name.entry']
rather than object keys?
The goal is to have an array sorted according to deeply nested properties.
const data = _.orderBy(array_of_objects, ['type.id','name.entry'], ['asc', 'desc']); - instead of keys
I am curious about this possibility because lodash provides access to an object's deep properties using _.get() as demonstrated below.
_.get(object, 'a[0].b.c');
// => 3
This makes me wonder if it can be achieved with _.orderBy() as well.
NB If there is a way to do this in vanilla JavaScript, please advise accordingly.
In my current scenario, I am facing difficulty sorting by multiple deeply nested props ['type.id','name.entry']
, where only one seems to work at a time.
If achieving this directly is not possible, suggestions on how to sort an array of objects with deeply nested properties based on multiple deeply nested props passed as string paths would be highly appreciated.