Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

shuffle an array

let array = [1, 2, 3, 4, 5];

for(let i = array.length - 1; i >= 1; i--) {
   let j = Math.floor(Math.random() * (i + 1)); // 0 <= j <= i
   let temp = array[j];
   array[j] = array[i];
   array[i] = temp;
}
console.log(array);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #shuffle #array
ADD COMMENT
Topic
Name
9+5 =