The object to iterate over.
The function invoked per iteration.
The custom accumulator value.
Returns the accumulated value.
5.11.0
[[reduce]], [[reduceRight]]
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'] }
An alternative to
reduce
this method transformsobject
to a newaccumulator
object which is the result of running each of its own enumerable string keyed properties thruiteratee
, with each invocation potentially mutating theaccumulator
object. Ifaccumulator
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 returningfalse
.