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);