Skip to content
Related Articles

Related Articles

Improve Article
Lodash _.unzipWith() Method
  • Last Updated : 31 Aug, 2020

The _.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: This method accepts two parameters as mentioned above and described below:

  • 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: Here, const _ = require(‘lodash’) is used to import the lodash library into the file.



Javascript




// Requiring the lodash library  
const _ = require("lodash"); 
   
// Original array
var 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:  

Javascript




// Requiring the lodash library  
const _ = require("lodash"); 
   
// Original array
var 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]
My Personal Notes arrow_drop_up
Recommended Articles
Page :