Skip to content
Related Articles
Open in App
Not now

Related Articles

Collect.js | combine() Method

Improve Article
Save Article
  • Last Updated : 16 Aug, 2021
Improve Article
Save Article

Collect.js is a fluent and convenient wrapper for working with arrays and objects. The JavaScript array is first transformed into a collection and then the function is applied to the collection.
The combine() method combines two different arrays with keys-values.


  • Collect.js can be installed via NPM: 
npm install --save collect.js
  • You can also use CDN of collect.js 
<script src=""></script>



Parameters: The collect() takes one argument that is keys converted into the collection and then combine() function takes one argument that are values
Return Value: Returns an object.
Below example illustrate the combine() methodin JavaScript: 
Example: Here collect = require(‘collect.js’) is used to import the collect.js library into the file. 


const collect = require('collect.js');
let keys = ['name', 'language']
let values = ['collect.js', 'js']
// convert keys into collection
const collection = collect(keys);
const object = collection.combine(values)
// returning the object
let newObject =  object.all();
console.log("Single array: ", newObject);


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!