Last active
December 11, 2015 05:44
-
-
Save tim545/4cddce0c65e86aca5b4a to your computer and use it in GitHub Desktop.
Add a method to the Array prototype to return a random array item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adds a method to the Array prototype to return a random array item | |
Array.prototype.random = function() { | |
return this[Math.floor(Math.random() * this.length)]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment