去除字符串中重复的字符
作者:互联网
方法一
function remove(str){
let result = '';
for(let i =0;i<str.length;i++){
let char = str[i];
if(result.indexOf(char) ==-1){
result += char;
}
}
return result;
}
let str='hellojavascript';
console.log(remove(str));
方法二
function remove(str){
let result = [];
let json = {};
for(let i =0;i<str.length;i++){
let char = str[i];
if(!json[char]){
result.push(char);
json[char] = true;
}
}
return result.join('');
}
let str = 'hellojavascript';
console.log(remove(str));
标签:function,字符,remove,json,let,result,str,去除,字符串 来源: https://www.cnblogs.com/Eamon-18/p/16361669.html