代码如下:
function checkMax(arr){ var result = [],hash ={}; for (var i = 0; i < arr.length; i++) { if (!hash[arr.charAt(i)]) { hash[arr.charAt(i)] = 1; }else{ hash[arr.charAt(i)]++; } } var key = '', value = 0; for(var i in hash){ if (hash[i]>value) { value = hash[i]; key = i; } } return 'Maximum num of the ele is------'+key+"-------And it's value is----- "+value; } var a = 'dajldkjalsdjalsdjassldahf'; alert(checkMax(a));