Lodash – sample method

  • Post author:
  • Post category:Lodash
  • Post comments:1 Comment
Lodash - sample method

Syntax Of Lodash sample method

_.sample(collection)

Lodash sample method Gets a random element from the collection.

Arguments

  • collection (Array|Object) − The collection to sample.

Output

  • (*) − Returns the random element.

Example

var _ = require('lodash');
var list = [1, 2, 3, 4, 5]
var result = _.sample(list);
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

3

Next Topic – Click Here

This Post Has One Comment

Leave a Reply