var x = [1,2,2,3,4,5,6,7,7,8] var y = x[x.length-1] var z= [] for (var i = 0;i<x.length;i++) { if (y!=x[i]) { z.push(x[i]) y = x[i] } }