Skip to content
Related Articles

Related Articles

Improve Article
Collect.js | combine() Method
  • Last Updated : 30 Jun, 2020

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.

Installation:

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

Syntax:

collect(keys).combine(values)

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 onject
let newObject =  object.all();
  
console.log("Single array: ", newObject);

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :