sample source npm

_.sample(collection)

Gets a random element from collection.

Arguments

  1. collection (Array|Object)

    The collection to sample.

Returns (*)

Returns the random element.

Example

_.sample([1, 2, 3, 4]);
// => 2