The first kind of

var str = "abcccwwwasdasfqwweqewqeqwnn" var arr = str.split("") var Arr = arr.sort() let num=1; let max=""; let maxs=0; for(var i=0; i<Arr.length; i++){ if(Arr[i]==Arr[i+1]){ num++ }else{ if(num>maxs){ maxs=num max=Arr[i] } num=1 } } console.log(max, maxs)Copy the code

The second,

var str = "abcccwwwasdasfqwweqewqeqwnn"
    var arr = str.split("")
    var Arr = arr.sort()
    var strs = Arr.join("");
    var max = "";
    var maxs = 0
    strs.replace(/(\w)\1+/g, function (strs, strs2) {
        if (strs.length > maxs) {
            maxs = strs.length;
            max = strs2
        }
    })
    console.log(max, maxs)
Copy the code

The third kind of

var str = "abcccwwwasdasfqwweqewqeqwnn" var o={} for(var i=0; i<str.length; i++){ var name=str[i] if(o[name]){ o[name]++ }else{ o[name]=1 } } var max=0; var maxs="" for(var name in o){ if(max<o[name]){ max=name } } console.log(max,maxs)Copy the code