Sorts an array of objects by a specified property key.
Type of the items in the array.
The array to sort.
The key to sort by.
'asc' (default) or 'desc' for descending order.
A new array sorted by the specified key.
sortBy([{a: 3}, {a: 1}, {a: 2}], 'a'); // [{a: 1}, {a: 2}, {a: 3}]sortBy([{a: 'b'}, {a: 'a'}], 'a', 'desc'); // [{a: 'b'}, {a: 'a'}] Copy
sortBy([{a: 3}, {a: 1}, {a: 2}], 'a'); // [{a: 1}, {a: 2}, {a: 3}]sortBy([{a: 'b'}, {a: 'a'}], 'a', 'desc'); // [{a: 'b'}, {a: 'a'}]
Sorts an array of objects by a specified property key.