An alternative to `reduce` this method transforms `object` to a new `accumulator` object which is the result of running each of its own enumerable string keyed properties thru `iteratee`, with each invocation potentially mutating the `accumulator` object. If `accumulator` is not provided, a new object with the same `[[Prototype]]` will be used. The iteratee is invoked with four arguments: (accumulator, value, key, object). Iteratee functions may exit iteration early by explicitly returning `false`.
transform([2, 3, 4], (result, n) => {
result.push(n *= n)
return n % 2 == 0
}, [])
// => [4, 9]
transform({ 'a': 1, 'b': 2, 'c': 1 }, (result, value, key) => {
(result[value] || (result[value] = [])).push(key)
}, {})
// => { '1': ['a', 'c'], '2': ['b'] }
Name | Type | Attribute | Description |
---|---|---|---|
object | The object to iterate over. | ||
iteratee | The function invoked per iteration. | ||
accumulator | The custom accumulator value. |
*
{ "comment": "/**\r\n * An alternative to `reduce` this method transforms `object` to a new\r\n * `accumulator` object which is the result of running each of its own\r\n * enumerable string keyed properties thru `iteratee`, with each invocation\r\n * potentially mutating the `accumulator` object. If `accumulator` is not\r\n * provided, a new object with the same `[[Prototype]]` will be used. The\r\n * iteratee is invoked with four arguments: (accumulator, value, key, object).\r\n * Iteratee functions may exit iteration early by explicitly returning `false`.\r\n *\r\n * @since 1.3.0\r\n * @category Object\r\n * @param {Object} object The object to iterate over.\r\n * @param {Function} iteratee The function invoked per iteration.\r\n * @param {*} [accumulator] The custom accumulator value.\r\n * @returns {*} Returns the accumulated value.\r\n * @see reduce, reduceRight\r\n * @example\r\n *\r\n * transform([2, 3, 4], (result, n) => {\r\n * result.push(n *= n)\r\n * return n % 2 == 0\r\n * }, [])\r\n * // => [4, 9]\r\n *\r\n * transform({ 'a': 1, 'b': 2, 'c': 1 }, (result, value, key) => {\r\n * (result[value] || (result[value] = [])).push(key)\r\n * }, {})\r\n * // => { '1': ['a', 'c'], '2': ['b'] }\r\n */", "meta": { "range": [ 1386, 2053 ], "filename": "transform.js", "lineno": 36, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100010375", "name": "transform", "type": "FunctionDeclaration", "paramnames": [ "object", "iteratee", "accumulator" ] }, "vars": { "isArr": "transform~isArr", "isArrLike": "transform~isArrLike", "Ctor": "transform~Ctor", "accumulator": "transform~accumulator", "": null } }, "description": "An alternative to `reduce` this method transforms `object` to a new\r`accumulator` object which is the result of running each of its own\renumerable string keyed properties thru `iteratee`, with each invocation\rpotentially mutating the `accumulator` object. If `accumulator` is not\rprovided, a new object with the same `[[Prototype]]` will be used. The\riteratee is invoked with four arguments: (accumulator, value, key, object).\rIteratee functions may exit iteration early by explicitly returning `false`.", "since": "1.3.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Object", "value": "Object" } ], "params": [ { "type": { "names": [ "Object" ] }, "description": "The object to iterate over.", "name": "object" }, { "type": { "names": [ "function" ] }, "description": "The function invoked per iteration.", "name": "iteratee" }, { "type": { "names": [ "*" ] }, "optional": true, "description": "The custom accumulator value.", "name": "accumulator" } ], "returns": [ { "type": { "names": [ "*" ] }, "description": "Returns the accumulated value." } ], "see": [ "reduce, reduceRight" ], "examples": [ "transform([2, 3, 4], (result, n) => {\r result.push(n *= n)\r return n % 2 == 0\r}, [])\r// => [4, 9]\r\rtransform({ 'a': 1, 'b': 2, 'c': 1 }, (result, value, key) => {\r (result[value] || (result[value] = [])).push(key)\r}, {})\r// => { '1': ['a', 'c'], '2': ['b'] }" ], "name": "transform", "longname": "transform", "kind": "function", "scope": "global", "___id": "T000002R000945", "___s": true, "filepath": "transform.js" }