<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Max_val</title>
</head>
<body>
<div class="">
</div>
</body>
<script type="text/javascript" charset="utf-8">
//将字符串的字符保存在一个hash table中,key是字符,value是这个字符出现的次数
var str = "abcdefgadddaaaaaaaaab";
var obj = {};
for (var i = 0, l = str.length; i < l; i++)
{
var key = str[i];
if (!obj[key])
{
obj[key] = 1;
}
else
{
obj[key]++;
}
}
/*遍历这个hash table,获取value最大的key和value*/
var max = 0;
var max_key = "";
for (index in obj)
{
if (max < obj[index])
{
max = obj[index];
max_key = index;
}
}
alert("max_count:"+max+" max_key:"+max_key);
</script>
</html>