Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

transform

v4.17.11arrow_drop_down
v4.17.11
STATUS
Passing
DOWNLOADS
10
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
10 months ago
SIZE
7 KB
An alternative to `_
1 contributor
Use transform in your project ?
Copied
npm i @bit/lodash.lodash.transform
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
  [2, 3, 4],
  function(result, n) {
    result.push((n *= n));
    return n % 2 == 0;
  },
  [],
modifieddraft
chevron_left
chevron_right
transform (
object:Object,
iteratee:Function?,
accumulator:*?
) : *

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.

Example
_.transform([2, 3, 4], function(result, n) {
  result.push(n *= n);
  return n % 2 == 0;
}, []);
// => [4, 9]

_.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  (result[value] || (result[value] = [])).push(key);
}, {});
// => { '1': ['a', 'c'], '2': ['b'] }
Arguments
object: Object

The object to iterate over.

iteratee: Function?

The function invoked per iteration.

accumulator: *?

The custom accumulator value.

Returns
*

Returns the accumulated value.