Sunday, January 18, 2026
HomeLanguagesJavascriptCollect.js | zip() Function

Collect.js | zip() Function

The zip() function is used to combine the values of given array with the values of original collection at a given index. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.

Syntax: 

data.zip(value)

Parameters: This function accept a single parameter as mentioned above and described below:

  • values :  This parameter holds the values in the new array. 

Return value :  Return a new collection by margin the value with the main collection one by one.
 

Below examples illustrate the zip() function in collect.js:
Example 1: Here in this example, we take a collection and then using the zip() function we matched them with a array of corresponding items of a new collection using the zip() method

Javascript




// It is used to import collect.js library 
const collect = require('collect.js');
  
const fruits = collect(['Apple', 'Banana']);
const quantity = fruits.zip([10, 15]);
  
console.log(quantity.all());


Output: 

[ Collection { items: [ 'Apple', 10 ] },
  Collection { items: [ 'Banana', 15 ] } ]

Example 2: 

Javascript




// It is used to import collect.js library  
const collect = require('collect.js');
  
const people = collect(['Ram', 'Sham']);
const age = people.zip([20, 25]);
  
console.log(age.all());


Output: 

[ Collection { items: [ 'Ram', 20 ] },
  Collection { items: [ 'Sham', 25 ] } ]

Reference: https://collect.js.org/api/zip.html

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS