-
keyBy()
介绍
遍历
collection
生成一个自定义 key 对应每个collection
元素的 对象_.keyBy(collection, [iteratee=_.identity])
用法
```javascript var array = [ { ‘dir’: ‘left’, ‘code’: 97 }, { ‘dir’: ‘right’, ‘code’: 100 } ];
const info = _.keyBy(array, function(o) { return o.code }); // { ‘97’: { dir: ‘left’, code: 97 }, ‘100’: { dir: ‘right’, code: 100 } }
_.keyBy(array, ‘dir’) //{ left: { dir: ‘left’, code: 97 }, right: { dir: ‘right’, code: 100 } } ```