var a = [1,1,2,3,4,4,1,5,1,6,1,1,7,1,1,7,1,1,7,1,1,1,8], i = a.length; a.sort(); while (i--) { if (a[i] == a[i-1]) { a.splice(i, 1); } }