sample()

Takes an array and returns a new array with some or all of the original values not usually in the same order.

This function is valid in v2.0.0 to v2.12.0. This function has been downloaded 12 times.

Parameters

{Array} arr
Array to create a new sample array from.
{number=} opt_count Optional, Default:1
Number of items to put in the sample array. Cannot exceed arr.length.

Returns

{Array}
Sample array of random elements picked from arr.

Required Functions

This function requires the following functions which are included automatically:

  • has()
    Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object; unlike the in operator, this method does not check down the object's prototype chain.
  • slice()
    Slice does not modify the original array, but instead returns a shallow copy of elements from the original array.