var str = "dasdafdasftrdhsdgrfergasfsgjghkjgf" let sArr = str.split(''); sArr = [...new Set(sArr)]; let cArr = []; sArr.forEach(item => { let re = eval(`/${item}/ig`); let o = {s:item,count:0} o.count = str.match(re).length; cArr.push(o) }) cArr.sort((a,b) => { return b.count - a.count; }) let maxCount = cArr[0].count; let fArr = cArr.filter(item => { return item.count == maxCount; }) console.log(fArr)
。