Lodash - zip method



Syntax

_.zip([arrays])

Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.

Arguments

  • [arrays] (...Array) − The arrays to process.

Output

  • (Array) − Returns the new array of grouped elements.

Example

var _ = require('lodash');
 
var result = _.zip(['a', 'b'], [1, 2], [true, false]);
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ [ 'a', 1, true ], [ 'b', 2, false ] ]
lodash_array.htm
Advertisements