SOURCE

var str = "bianchengsanmei,xuexiyouqudezhishi,jieshiyouqudepengyou,suzaoyouqudelinghun.";
function findMost (arr) {
  var maxNum = 0;
  var maxVal = 0;
  var maxVals = [];
  var obj = {};
  arr.forEach((iterm, index) => {
    if (obj[iterm]) {
      obj[iterm] = obj[iterm] + 1;
    } else {
      obj[iterm] = 1;
    }
    // 只能找到一个
    if (maxNum < obj[iterm]) {
      maxNum = obj[iterm];
      maxVal = iterm;
    }
  });
  console.log(obj);
  // 如果有多个的话需要遍历对象
  for (const key in obj) {
    if (obj[key] === maxNum) {
      maxVals.push(key);
    }
  }
  return { maxNum, maxVal, maxVals };
}
var result = findMost(str.split(''));
console.log(result);
console 命令行工具 X clear

                    
>
console