var arr = [1,2,3,4,5,6,7,9] function shuffle(arr){ let m = arr.length; while(m>1){ let index = ~~(Math.random()*m--); [arr[index], arr[m]] = [arr[m], arr[index]] } return arr; } console.log(shuffle(arr))