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...

20th Nov 2016, 2:51 PM
Big_Bear
Big_Bear - avatar
1 Odpowiedź
+ 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; }
20th Nov 2016, 3:08 PM
Aditya kumar pandey
Aditya kumar pandey - avatar