大家好!我叫戴向天
QQ群:602504799
QQ:809002582
function removeDuplicateChar(str){
if(!str)return ''
str = str.toString()
for(let i=0;i < str.length;i++){
let charStr = str[i]
let okStr = str.substring(0,i+1)
let surplus = str.substring(i+1,str.length)
surplus = surplus.replace(new RegExp('\\'+charStr, "gm"), '');
str = okStr + surplus
}
return str
}
const strOne = "aaaaaaaaabbbababababababbacdjkabacdjkabacdjkabacdjkaaaergds"
console.log(strOne)
console.log(removeDuplicateChar(strOne))
方法二:
const str = 'aaaabbbbccccadfyabfnsldnfas;';
str.split('').reduce((a,s)=>{
(a.indexOf(s)<0&&a.push(s));
return a
},[]).join('')