💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## countBy + [link](./countBy "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L7504 "View in source.") + [npm](https://www.npmjs.com/package/lodash.countby "See the npm package.") ``` _.countBy(collection, [iteratee=_.identity]) ``` 创建一个组成对象,key是经过 `iteratee` 处理的集合的结果,value 是处理结果的次数。 `iteratee` 会传入一个参数:(value)。 ### 参数 1. collection (Array|Object) 需要遍历的集合 2. [iteratee=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (Object) 返回一个组成汇总的对象 ### 示例 ``` _.countBy([6.1, 4.2, 6.3], Math.floor); // => { '4': 1, '6': 2 } _.countBy(['one', 'two', 'three'], 'length'); // => { '3': 2, '5': 1 } ```