The wrap() method in collect.js is used to wrap a particular set of values in a collection.
Installation:
- In NodeJs:
npm install collect.js
Syntax:
wrap( object );
Parameters: This method accepts an array or object.
Return Value: It returns the object.
Example 1:
Javascript
const collect = require( 'collect.js' );
let obj1 = { "a" : 1, "b" : 12, "c" : 3 };
let collection = collect();
collection.wrap(obj1);
console.log(collection.all());
collection = collect().wrap(obj1);
console.log(collection.all());
|
Output:
Example 2:
Javascript
const collect = require( 'collect.js' );
let obj1 = { "a" : 1, "b" : 12, "c" : 3 };
let obj2 = { "aa" : 1, "bb" : 12, "cc" : 3 };
let obj3 = { "aaa" : 1, "bbb" : 12, "ccc" : 3 };
collection = collect().wrap(obj1)
.wrap(obj2)
.wrap(obj3);
console.log(collection.all());
collection = collect().wrap(obj1)
.wrap(obj2)
console.log(collection.all());
|
Output:
Reference: https://collect.js.org/api/wrap.html
Last Updated :
29 Jul, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...