用js实现读取出字符串中每个字符重复出现的次数?
<script> var str="dfjkfkhsdjk hksjh", i=0, obj={}; for(i=0;i<str.length;i++) { var ch=str.charAt(i); if (!obj[ch]) { obj[ch]=1; } else{ obj[ch]++; } } for(var r in obj) { console.log(r+","+obj[r]); } </script>
<script> var str="dfjkfkhsdjk hksjh", i=0, obj={}; for(i=0;i<str.length;i++) { var ch=str.charAt(i); if (!obj[ch]) { obj[ch]=1; } else{ obj[ch]++; } } for(var r in obj) { console.log(r+","+obj[r]); } </script>