Collect.js | transform() Function Last Updated : 04 Jun, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The transform() function iterates over a collection and callback each item in the collection, the items inside the collection are replaced by the new callback values. It is similar to the JavaScript map() function but the values got replaced in transform() function. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.transform(item, key) Parameters: This function accepts two parameter as mentioned above and described below: item: This parameter holds the collection item. key: This parameter holds new operational value. Return Value: Returns an modified array which is created by this function. Below examples illustrate the transform() function in collect.js Example 1: Here in this example, we take a collection and then using the transform() function modified the values using the key transformation parameter and return the new value. JavaScript // It is used to import collect.js library const collect = require('collect.js'); const data= collect([1, 2, 3, 4, 5]); data.transform((item, key) => item * 5); console.log(data.all()); Output: [5 , 10 , 15 , 20 , 25 ] Example 2: Same thing we have done here as above example. JavaScript // It is used to import collect.js library const collect = require('collect.js'); const x= collect([10, 20, 30, 40, 50]); x.transform((item, key) => item / 10); console.log(x.all()); Output: [1 , 2 , 3 , 4 , 5 ] Reference: https://collect.js.org/api/transform.html Comment More infoAdvertise with us Next Article Collect.js | when() Function A akhilsharma870 Follow Improve Article Tags : JavaScript Web Technologies Collect.js Similar Reads Collect.js tap() Function Collect.js is a fluent and convenient wrapper for working with arrays and objects. The tap() function accepts the collection as a parameter and without affecting the collection it allows the user to tap into the collection at a specific point and do anything with the item. Installation:Â Install the 1 min read Collect.js | push() Function The push() function is used to add a new value to the end of the collection. Â In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax:Â data.push(value) Parameters: This function accepts a single parameter as mentioned above and describe 1 min read Collect.js make() Function Collect.js is a fluent and convenient wrapper for working with arrays and objects. The make() function creates a new collection instance. Installation:Â Install the Collect.js module using the following command: npm install --save collect.jsSyntax:Â Â collection.make(user collection)Parameters: This f 2 min read Collect.js | when() Function The when() function is used to callback if the first argument in the given proves to be true. In JavaScript, the array is first converted to a collection and then the function is applied to the collection.Syntax:Â data.when(conditional ,rule) Parameters:Â This function accept two parameters as mentio 1 min read Collect.js whereIn() Function The whereIn() function is used to filter the collection by a given key or value contained within the given array. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.whereIn('key') Parameters: This function accepts a single par 2 min read Collect.js where() Function The where() function is used to filter the collection by a given key or value contained within the given array. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.where('key') Parameters: This function accepts a single paramet 2 min read Like