Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript shuffle an array

const shuffleArray = (arr) => arr.sort(() => 0.5 - Math.random());

console.log(shuffleArray([1, 2, 3, 4]));
// Result: [ 1, 4, 3, 2 ]
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #javascript #shuffle #array
ADD COMMENT
Topic
Name
2+7 =