var ary=[1,2,3,4,5,6,7,8] function shuffle(arr) { arr.sort(function () { return Math.random() - 0.5; }); } shuffle(ary)