<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script> var a = ‘abcdeeffffffjjjjjjjjjjj‘; var b = {}; for (var i = 0;i < a.length;i++){ if (!b[a[i]]) { b[a[i]] = 1; }else { b[a[i]] = b[a[i]] + 1; }console.log(b[a[i]]); } var s = ‘‘; var iNum = 0; for (var name in b){ if (iNum < b[name]) { iNum = b[name]; s = name; } } alert(‘出现次数最多的字母是:‘ + s + ‘,出现了‘ + iNum + ‘次.‘); </script></head><body> </body></html>
原文地址:https://www.cnblogs.com/yxs1530/p/10242395.html
时间: 2024-10-14 20:58:13