Last active
October 5, 2015 11:43
-
-
Save Zorgatone/1ee94e74f4dfdd962d16 to your computer and use it in GitHub Desktop.
Get random array element, directly from the object
This file contains hidden or 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
| /** | |
| * Get random array element, directly from the object | |
| */ | |
| Array.prototype.random = Array.prototype.random || function random() { | |
| return this[Math.floor(Math.random() * this.length)]; | |
| }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: