Possible Duplicates:
JavaScript: Getting random value from an array
How can I choose an object key at random?
suppose we have an array like this:
var MrArray = new Array(5);
MrArray['one']='oneValue';
MrArray['two']='twoValue';
MrArray['three']='threeValue';
MrArray['four']='fourValue';
MrArray['five']='fiveValue';
ok?
the Array is associated.
and we have string key and string value.
now! how can i pick a random value from that?
Edit:i want to use like this:
<A href="Array value Here">Array Key Here</a>
Regards
Sam
Using the method described here we can create the following function:
It returns a random key, so to get a random value from
MrArray, do this:jsPerf benchmark comparing the speed of this and the other answer.