let a = "aaaaaaaaadsdfdfdfeeeeeeee"; let json = {} for(let i=0;i<a.length;i++){ if(!json[a[i]]){ json[a[i]] =1 }else{ json[a[i]]++ } } console.log(json) let maxNum = 0 let maxStr; for(let i in json){ if(json[i]>maxNum){ maxNum = json[i] maxStr = i } } console.log("出現次數最多的字符是"+maxStr+",出現了"+maxNum+"次")