var str = "1,2,4,5,2,4"; var s = str.split(','); var dic = {}; for (var i = s.length; i--; ) { dic[s[i]]=s[i]; } var r = []; for (var v in dic) { r.push(dic[v]); } alert(r.join());