Open In App

Lodash _.unzip() Method

Last Updated : 30 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.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:

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

Return Value:

This method is used to return the new array of regrouped elements.

Example 1: In this example, we are grouping the given array by the use of the lodash _.unzip() method.

javascript




// Requiring the lodash library
const _ = require("lodash");
 
// Original array
let 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: In this example, we are grouping the given array by the use of the lodash _.unzip() method.

javascript




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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads