function fn(str) { var obj = {}; for (var i = 0; i < str.length; i++) { if (!obj[str.charAt(i)]) { obj[str.charAt(i)] = 1; } else { obj[str.charAt(i)]++; } } var value = ‘‘; var count = 0; for (var i in obj) { if (obj[i] > count) { count = obj[i]; value = i; } } console.log(‘出现次数最多的是‘ + value + ‘,出现次数为‘ + count); }
原文地址:https://www.cnblogs.com/gxx129/p/10981406.html
时间: 2024-10-13 15:04:35