AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
## groupBy + [link](./groupBy "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L7749 "View in source.") + [npm](https://www.npmjs.com/package/lodash.groupby "See the npm package.") ``` _.groupBy(collection, [iteratee=_.identity]) ``` 创建一个对象组成,key 是经 iteratee 处理的结果, value 是产生 key 的元素数组。 iteratee 会传入1个参数:(value)。 ### 参数 1. collection (Array|Object) 需要遍历的集合 2. [iteratee=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (Object) 返回一个组成汇总的对象 ### 示例 ``` _.groupBy([6.1, 4.2, 6.3], Math.floor); // => { '4': [4.2], '6': [6.1, 6.3] } // 使用了 `_.property` 的回调结果 _.groupBy(['one', 'two', 'three'], 'length'); // => { '3': ['one', 'two'], '5': ['three'] } ```