Lodash _.zip() Method

The _.zip() method is used to create an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second element of the given arrays, and so on.

Syntax:

_.zip([arrays])

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

  • [arrays]: This parameter holds the arrays to process.

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

a,1,true,b,2,false,c,3,true

Example 2:  

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash"); 
  
// Use of _.zip()  
// method 
let gfg = _.zip(['Amit', 'Akash', 'Avijit'], 
                [1, 2, 3], 
                ['pass', 'pass', 'fail']);
        
// Printing the output  
console.log(gfg)

chevron_right


Output:

Amit,1,pass,Akash,2,pass,Avijit,3,fail

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.