美文网首页
字符串去重

字符串去重

作者: 63537b720fdb | 来源:发表于2020-07-01 21:56 被阅读0次

和数组去重的原理相同

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;
}

相关文章

网友评论

      本文标题:字符串去重

      本文链接:https://www.haomeiwen.com/subject/vwhkqktx.html