Lodash_.unzipWith() method accepts iteratee to specify how regrouped values should be combined. The iteratee is invoked with the elements of each group.
Syntax:
_.unzipWith(array, [iteratee = _.identity]);
Parameters:
- array: This parameter holds the array of grouped elements to process.
- [iteratee = _.identity]: This parameter holds the function to combine regrouped values.
Return Value:
This method returns the new array of regrouped elements.
Example 1: In this example, we are unzipping the given zipped array and using the subtract method for subtracting the values of that array.
Javascript
// Requiring the lodash library const _ = require( "lodash" );
// Original array let zipped_arr = _.zip([15, 7], [185, 20], [478, 123]); // Use of _.unzipWith() method let gfg = _.unzipWith(zipped_arr, _.subtract); // Printing the output console.log(gfg); |
Output:
[8, 165, 355]
Example 2: In this example, we are unzipping the given zipped array and using the add method for adding the values of that array.
Javascript
// Requiring the lodash library const _ = require( "lodash" );
// Original array let zipped_arr = _.zip([4, 9], [185, 20], [478, 123]); // Use of _.unzipWith() method let gfg = _.unzipWith(zipped_arr, _.add); // Printing the output console.log(gfg) |
Output:
[13, 205, 601]