Shuffle array elements and display randomly using javascript - Javascript Views : 1145
Tagged in : Javascript
1 0
Send mail
Hi...

Use the following code to shuffle the array elements and display randomly.

<script type="text/javascript">
shuffle = function(o)
{
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
var arr =new Array(1,2,3,4,5,6,7);
var shuff=shuffle(arr);
alert(arr);
</script>
By Nirmala, On - 2008-10-13



    Login to add Comments .