var str = '1+1+2+2+2+2'; str = str.split('+').filter(function(value, i, arr) { return arr.lastIndexOf(value) == i; }).join('+'); alert(str);