You-Dont-Need-Lodash-Underscore
You-Dont-Need-Lodash-Underscore copied to clipboard
How do you replace lodash to sort an array of objects by object key?
How do you replace lodash to sort an array of objects by object ('foo') key ('bar')?
_.sortBy(myarray, 'foo.bar')
@gilles6 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
I've been using this plugin, and running into stuff like this; I may try coming up with some updates to submit based on my findings.
This is probably one of the reasons the docs say (may not) need lodash
Likely a few steps needed here for this replacement
- copy the array: spread or concat
- properties by dot notation string: split, reduce (with null/object checks)
- comparator function used with native sort
Note that lodash also allows multi field sorting, _.sortBy(users, ['user', 'age']), which would add to the complexity