0
How can I shuffle an array in JS script?
Well, I have been facing this problem since last week my IT teacher told to make a random selector...
1 ответ
+ 4
Use this below code this function shuffle array elements
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}