Random sort an array of string
<html>
<head>
<title>Array literal</title>
<script type="text/javascript" >
function compare(a, b)
{
if (Math.random() * 2 > 1) { return 1; }
else { return -1; }
}
var planets = ['m', 'a', 'e', 'm', 'j'];
planets.sort(compare);
document.write(planets);
</script>
</head>
<body>
</body>
</html>
Related examples in the same category