直接上代码 let str = 'aaassddddddffffffhhhhh'; let a = 0,b = 1,c = 0,d = ''; while(a < str.length){ if(str[a] != str[b]){ if(b - a > c){ c = b - a; d = str[a]; } a = b; } b++; } console.log('重复最多的字符:',d);