![]() |
VOOZH | about |
Lodash _.transform() method is an alternative to the _.reduce() method transforms an object to a new accumulator object which is the result of running each of its own enumerable string keyed properties through iteratee with each invocation potentially mutating the accumulator object. A new object with the same prototype will be used if an accumulator is not provided.
_.transform(object, iteratee, accumulator);This method returns the accumulated value.
Example 1: In this example, we are transforming the given array by the use of the lodash _.transform() method.
Output:
144, 169Example 2: In this example, we are transforming the given array by the use of the lodash _.transform() method.
Output:
{ '3': ['p', 'r'], '6': ['q'] }Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.