Collect.js | random() function Last Updated : 05 Jun, 2020 Comments Improve Suggest changes Like Article Like Report The random() function as the name suggest it returns any random value from the collection. In JavaScript, the array is first converted to a collection and then the function is applied to the collection. Syntax: data.random(number) Parameters: This function accept a single parameter as mentioned above and described below number: This parameter holds the integer number that how many random number should return from the collection. Return Value: Returns random value or values from collection. Below examples illustrate the random() function in collect.js Example 1:Return single random value. JavaScript // It is used to import collect.js library const collect = require('collect.js'); let main = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const data = collect(main); let x = data.random(); console.log(x); Output: 6 Example 2: Return multiple random values. JavaScript // It is used to import collect.js library const collect = require('collect.js'); let main = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const data = collect(main); let x2 = data.random(2); console.log(x2.all()); Output: [5 , 7] Reference: https://collect.js.org/api/random.html Comment More infoAdvertise with us Next Article Collect.js | random() function 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 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 | zip() Function 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. Syntax:Â data.zip(value) Parameters:Â This function accept a single 2 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 Like