🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 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'] } ```