Creates an object composed of keys generated from the results of running each element of `collection` thru `iteratee`. The corresponding value of each key is the last element responsible for generating the key. The iteratee is invoked with one argument: (value).
const array = [
{ 'dir': 'left', 'code': 97 },
{ 'dir': 'right', 'code': 100 }
]
keyBy(array, ({ code }) => String.fromCharCode(code))
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
| Name | Type | Attribute | Description |
|---|---|---|---|
| collection | The collection to iterate over. | ||
| iteratee | The iteratee to transform keys. |
{
"comment": "/**\r\n * Creates an object composed of keys generated from the results of running\r\n * each element of `collection` thru `iteratee`. The corresponding value of\r\n * each key is the last element responsible for generating the key. The\r\n * iteratee is invoked with one argument: (value).\r\n *\r\n * @since 4.0.0\r\n * @category Collection\r\n * @param {Array|Object} collection The collection to iterate over.\r\n * @param {Function} iteratee The iteratee to transform keys.\r\n * @returns {Object} Returns the composed aggregate object.\r\n * @see groupBy, partition\r\n * @example\r\n *\r\n * const array = [\r\n * { 'dir': 'left', 'code': 97 },\r\n * { 'dir': 'right', 'code': 100 }\r\n * ]\r\n *\r\n * keyBy(array, ({ code }) => String.fromCharCode(code))\r\n * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }\r\n */",
"meta": {
"range": [
921,
1088
],
"filename": "keyBy.js",
"lineno": 26,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100005496",
"name": "keyBy",
"type": "FunctionDeclaration",
"paramnames": [
"collection",
"iteratee"
]
},
"vars": {
"": null
}
},
"description": "Creates an object composed of keys generated from the results of running\reach element of `collection` thru `iteratee`. The corresponding value of\reach key is the last element responsible for generating the key. The\riteratee is invoked with one argument: (value).",
"since": "4.0.0",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Collection",
"value": "Collection"
}
],
"params": [
{
"type": {
"names": [
"Array",
"Object"
]
},
"description": "The collection to iterate over.",
"name": "collection"
},
{
"type": {
"names": [
"function"
]
},
"description": "The iteratee to transform keys.",
"name": "iteratee"
}
],
"returns": [
{
"type": {
"names": [
"Object"
]
},
"description": "Returns the composed aggregate object."
}
],
"see": [
"groupBy, partition"
],
"examples": [
"const array = [\r { 'dir': 'left', 'code': 97 },\r { 'dir': 'right', 'code': 100 }\r]\r\rkeyBy(array, ({ code }) => String.fromCharCode(code))\r// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }"
],
"name": "keyBy",
"longname": "keyBy",
"kind": "function",
"scope": "global",
"___id": "T000002R000516",
"___s": true,
"filepath": "keyBy.js"
}