和数组去重的原理相同
String.prototype.strUnique = function() {
var temp = {},
str = "",
len = this.length;
for(var i = 0; i < len; i++) {
if(!temp[this[i]]) {
temp[this[i]] = '123';
str += this[i]
}
}
console.log(temp);
return str;
}
网友评论