<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
输入一个字符串,统计该字符串中每个字符出现的次数
var str = "aabbccddeeef";
var strNew = {};创建一个空的对象
for(var i=0; i<str.length; i++){
var num = str[i];
if (!strNew[num]) {
strNew[num] = 1;
}else {
strNew[num] += 1;
}
}
console.log(strNew);
</script>
</body>
标签:字符,次数,js,字符串,var,统计
From: https://www.cnblogs.com/hqingxiang/p/17289586.html