This method is like _.max except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked.
yarn add @jswork/next-max-by
import '@jswork/next-max-by';
const arr = [
{ name: 'apple', value: 1 },
{ name: 'banana', value: 2 },
{ name: 'orange', value: 3 },
{ name: 'pear', value: 4 },
{ name: 'grape', value: 5 }
];
const result = nx.maxBy(arr, (x) => x.value);
console.log(result);
// { name: 'grape', value: 5 }
Code released under the MIT license.