JS array shuffle using prototype

by Prabakaran 2012-07-30 14:31:22

<script type="text/javascript">
Array.prototype.shuffle = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]);
while (s.length) this.push(s.pop());
return this;
}

var myary = [1,2,3,4];
myary.shuffle();

alert(myary)
</script>
834
like
0
dislike
0
mail
flag

You must LOGIN to add comments