Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Lodash _.unzip() Method

  • Last Updated : 28 Aug, 2020

The _.unzip method is similar to _.zip (i.e.; it creates an array of grouped elements) except that it accepts an array of grouped elements and also creates an array regrouping the elements to their pre-zip configuration.

Syntax:

_.unzip(array)

Parameters: This method accepts a single parameters as mentioned above and described below:

  • array (Array): This parameter holds the array of grouped elements to process.

Return Value: This method is used to returns the new array of regrouped elements.

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.

javascript




// Requiring the lodash library 
const _ = require("lodash"); 
      
// Original array 
var zipped = _.zip(['a', 'b'], [1, 2], [true
  
false]);    
  
// Use of _.zip() 
// method
let gfg = _.zip(zipped);
      
// Printing the output 
console.log(gfg);

Output:

[ [['a', 1, true], ['b', 2, false]] ]

Example 2:

javascript




// Requiring the lodash library 
const _ = require("lodash"); 
      
// Original array 
var zipped = (['x', 'y'], [5, 6], [true, false]);    
  
// Use of _.zip() 
// method
let gfg = _.zip(zipped);
      
// Printing the output 
console.log(gfg);

Output:

[ [true, false] ]

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!