Last active
November 16, 2016 18:54
-
-
Save mfd/2a8fd9e58c6f46144c576039eee0ff39 to your computer and use it in GitHub Desktop.
Get random item from JavaScript array
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
var items = ["a","e","i","o","u"]; | |
var objResults = {} | |
for(var i = 0; i < 1000000; i++){ | |
var randomElement = items[Math.floor(Math.random()*items.length)]; | |
if (objResults[randomElement]){ | |
objResults[randomElement]++ | |
} | |
else { | |
objResults[randomElement] = 1 | |
} | |
} | |
console.log(objResults) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment