VOOZH about

URL: https://www.geeksforgeeks.org/javascript/collect-js-random-function/

⇱ Collect.js | random() function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collect.js | random() function

Last Updated : 5 Jun, 2020

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.
 

Output: 

6


Example 2: Return multiple random values.

Output: 

[5 , 7]


Reference: https://collect.js.org/api/random.html

Comment
Article Tags: