A string of characters appears more than once, how the number of characters that appear most often and which it appears judge

var str = "asdkfhsodjcpeksoxshieorjsa";
    var obj = {};
    for(var i=0;i<str.length;i++){
        if(!obj[str.charAt(i)]){
            obj[str.charAt(i)] = 1;
        }else{
            obj[str.charAt(i)]++;
        }
    };
    var maxNum = 0;
    var letter = '';
    for(var i in obj){
        if(obj[i]>maxNum){
            maxNum =obj [I]; 
            Letter = I 
        } 
    } 
    the console.log ( 'largest number of occurrences is:' + letter + 'appear' + maxNum + 'views')

 

Guess you like

Origin www.cnblogs.com/shy0113/p/11517326.html