Skip to content
Related Articles

Related Articles

Collect.js | zip() Function

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 10 Jun, 2020

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.


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


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


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

Example 2: 


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


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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!