Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

shuffle

The following extension to the Array object is courtesy of the author. This method can be added via prototype to the Array object interface so that all arrays in a script can call it like they call their built-in methods.

Syntaxarray.shuffle()

This shuffle() method shuffles an array's elements according to the Fisher-Yates Shuffle Modern Algorithm.

Prototype the custom method(include this just once into your program upon start): Array.prototype.shuffle = function(){ var i = this.length, j, temp; while(--i > 0){ j = Math.floor(Math.random() * (i+1)); temp = this[j]; this[j] = this[i]; this[i] = temp; } return this; } Use the custom method on any arrays from that point on : var arr = ['A','B','C','D','E','F','G','H']; var result = arr.shuffle();

JavaScript

Methods

addEventListeneralertaveragebackblurconcatcreatedecodeURIdecodeURIComponentencodeURIencodeURIComponentevaleveryfilterforwardgoisArrayisFiniteisNaNjoinparseFloatparseIntpoppushpushStatereducereplaceStatereverseshiftshuffleslicesomesortspliceunshiftwrite