Created
December 3, 2012 19:28
-
-
Save johnpolacek/4197322 to your computer and use it in GitHub Desktop.
Get Random Array Item
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
var item = items[Math.floor(Math.random()*items.length)]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
items[~~(Math.random()*items.length)]
or Array.prototype.random = function(){return this[~~(Math.random() * this.length)]}