Switch to full style
JavaScript code examples
Post a reply

Shuffle Array

Mon Sep 19, 2011 12:17 pm

Shuffle and traversing array.You need to refresh to notice the shuffling.
Code:

<html>
<
title>Shuffle Array</title>
<
head>
<
script language="JavaScript">
function Shuffle(arr) {
    for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), 
    x 
= arr[--i], arr[i] = arr[j], arr[j] = x);
    return arr;
};

function ShuffleArray()
{
    var colorArr= Array("RED", "BLUE", "YELLOW");
    suffcolor=Shuffle(colorArr);
    // traverse array
    for (key in suffcolor)
    document.write("<br/>color value is " + suffcolor[key]);
}
 

</script>
</head>

<body>

 
<SCRIPT language="JavaScript">
 
ShuffleArray();
 
</SCRIPT>

</body>
</HTML>





Post a reply
  Related Posts  to : Shuffle Array
 Array shuffle     -  
 Array difference for associate array     -  
 compare an array with another array?     -  
 XML Document into an Array in php     -  
 Array C++ Class     -  
 Pop the element off the end of array     -  
 Here is how to display any 2d array     -  
 PHP Array Functions     -  
 Array Passing     -  
 Average of an array. Please help     -  

Topic Tags

JavaScript Arrays