function test1 (array) { return array.concat().sort(() => { return Math.random() - 0.5 }) } function test2 (array) { array = array.concat() let rand = 0 let tmp = null for(let i = 0; i < array.length; i++) { rand = i + Math.floor(Math.random() * (array.length - i)); // [array[i], array[rand]] = [array[rand], array[i]] tmp = array[i] array[i] = array[rand] array[rand] = tmp } return array } let array = [1, 2, 3, 4, 5, 6, 7, 8, 9] console.log(test2(array))