A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-zip-method/ below:

Lodash _.zip() Method - GeeksforGeeks

Lodash _.zip() Method

Last Updated : 03 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: Return Value:

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

JavaScript
// 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)

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.

JavaScript
// 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);

Output:

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4