Answers for "javascript random shuffle array"

11

how to randomly sort an array javascript

array.sort(() => Math.random() - 0.5);
Posted by: Guest on May-29-2021
1

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 ]
Posted by: Guest on September-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language