<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var str = "aabbbfkhskffskdhdkal"
var arr = {}
for(var i=0;i<str.length;i++){
if(arr[str[i]] == undefined){
arr[str[i]]=1;
}else{
arr[str[i]]+=1;
}
}
for(var x in arr){
document.write(`${x}出现的次数为${arr[x]}<br>`)
}
</script>
</body>
</html>
统计字符串出现的次数
最新推荐文章于 2023-10-28 01:40:45 发布