const str = "aaabbbcccc"; function findStr(str) { const obj = {}; for (let index = 0; index < str.length; index++) { const element = str[index]; obj[element] = obj[element] + 1 || 1 } // 找出出现最多的字符和次数 const maxNum = Math.max(...Object.values(obj)) //拿到次数 const arr = [] for (const key in obj) { if (obj[key] === maxNum) { arr.push({ chart: key, count: obj[key] }) } } return arr } console.log(findStr(str));