Creates a comparison function for sorting an array of objects by multiple keys.
The keys or sorting options to apply in priority order
A comparison function suitable for Array.prototype.sort()
Array.prototype.sort()
const arr = [{ a: 1, b: 'z' }, { a: 1, b: 'a' }];arr.sort(sortBy('a', { field: 'b', dir: 'desc' })); Copy
const arr = [{ a: 1, b: 'z' }, { a: 1, b: 'a' }];arr.sort(sortBy('a', { field: 'b', dir: 'desc' }));
Creates a comparison function for sorting an array of objects by multiple keys.