Lodash _.unzipWith() Method
Last Updated :
03 Nov, 2023
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
const _ = require( "lodash" );
let zipped_arr = _.zip([15, 7], [185, 20], [478, 123]);
let gfg = _.unzipWith(zipped_arr, _.subtract);
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
const _ = require( "lodash" );
let zipped_arr = _.zip([4, 9], [185, 20], [478, 123]);
let gfg = _.unzipWith(zipped_arr, _.add);
console.log(gfg)
|
Output:
[13, 205, 601]
Share your thoughts in the comments
Please Login to comment...