js shuffle array
yourArray.sort(function() { return 0.5 - Math.random() });
js shuffle array
yourArray.sort(function() { return 0.5 - Math.random() });
javascript randomly shuffle array
function randomArrayShuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var alphabet=["a","b","c","d","e"];
randomArrayShuffle(alphabet);
//alphabet is now shuffled randomly = ["d", "c", "b", "e", "a"]
shuffle an array of numbers in javascript
let numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411];
numbers = numbers.sort(function(){ return Math.random() - 0.5});
/* the array numbers will be equal for example to [120, 5, 228, -215, 400, 458, -85411, 122205] */
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us