Sorts an array by the values extracted by the iteratee function.
This function takes an array and a function that extracts a value from each element, and returns a new array sorted based on the extracted values.
The type of the elements in the array.
The type of the values extracted from the elements.
The array to sort.
The function to extract the value from each element.
const array = [ { name: 'John', age: 25 }, { name: 'Jane', age: 22 }, { name: 'Jack', age: 27 }];const sorted = sortBy(array, x => x.age);// sorted will be [// { name: 'Jane', age: 22 },// { name: 'John', age: 25 },// { name: 'Jack', age: 27 }// ] Copy
const array = [ { name: 'John', age: 25 }, { name: 'Jane', age: 22 }, { name: 'Jack', age: 27 }];const sorted = sortBy(array, x => x.age);// sorted will be [// { name: 'Jane', age: 22 },// { name: 'John', age: 25 },// { name: 'Jack', age: 27 }// ]
Sorts an array by the values extracted by the iteratee function.
This function takes an array and a function that extracts a value from each element, and returns a new array sorted based on the extracted values.