The function presented bellow can be used to shuffle /randomize array items in JavaScript.
// receive an array and return it with the items shuffled /randomized function shuffle(ar){ for(var j, x, i = ar.length; i; j = Math.floor(Math.random() * i), x = ar[--i], ar[i] = ar[j], ar[j] = x); return ar; }- Here is a simple example:
<h4>Example shuffle array in JavaScript</h4> <p>Initial array: ar1 = ['a', 'b', 'c', 1, 2, 3];</p> <button id='btntst'>Test Shuffle Array</button> <script> // receive an array and return it with the items shuffled /randomized function shuffle(ar){ for(var j, x, i = ar.length; i; j = Math.floor(Math.random() * i), x = ar[--i], ar[i] = ar[j], ar[j] = x); return ar; } var ar1 = ['a', 'b', 'c', 1, 2, 3]; //when click on the #btntst, show alert box with the items of ar1 document.getElementById('btntst').addEventListener('click', function(){ ar1 = shuffle(ar1); alert(ar1); }); </script>
<ul> <li>http://coursesweb.net/html/</li> <li>http://coursesweb.net/css/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net