ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## maxBy + [link](./maxBy "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L13952 "View in source.") + [npm](https://www.npmjs.com/package/lodash.maxby "See the npm package.") ``` _.maxBy(array, [iteratee=_.identity]) ``` 这个方法类似 `_.max` 除了它接受 `iteratee` 调用每一个元素,根据返回的 value 决定排序准则。 iteratee 会传入1个参数:(value)。 ### 参数 1. array (Array) 要遍历的数组 2. [iteratee=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (\*) 返回最大值 ### 示例 ``` var objects = [{ 'n': 1 }, { 'n': 2 }]; _.maxBy(objects, function(o) { return o.n; }); // => { 'n': 2 } // 使用了 `_.property` iteratee 的回调结果 _.maxBy(objects, 'n'); // => { 'n': 2 } ```