JS找重复项最多的字符和个数

 var str = 'sfdsklsjlsenlvkoaoemsfbsjdgsnsjksdslesmkfbnsgn';
 var arr = str.split('');
 str = arr.sort().join('');
 var value = '';
 var index = 0;
 var re = /(\w)\1+/g;

 str.replace(re,function($0,$1){
  if(index<$0.length){
    index = $0.length;
    value = $1;
  }
 });
 alert('最多的字符:'+value+',重复的次数:'+index);

你可能感兴趣的:(JS找重复项最多的字符和个数)