VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-zip-method/

⇱ Lodash _.zip() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.zip() Method

Last Updated : 3 Sep, 2024

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

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

Return Value:

  • This method returns the new array of regrouped elements.

Example 1: In this example, we are grouping our three arrays having different types of data by the use of the _.zip() method.

Output:

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

Example 2: In this example, we are grouping our three arrays having different types of data by the use of the _.zip() method.

Output:

[
[ 'Amit', 1, 'pass' ],
[ 'Akash', 2, 'pass' ],
[ 'Avijit', 3, 'fail' ]
]
Comment