var arr="dgdgjdgkdgjdgkdgjdgkdgagdgdddddddddd"; var newArr=arr.split(""); var json={}; var numArr=[]; var lagStr=null; var lagLen=null; newArr.map((item,index)=>{ json[item]=0; }); Object.keys(json).map((item,index)=>{ let b=new RegExp(item,"g"); let c=arr.match(b); json[item]=c.length; numArr.push(c.length); }) lagLen=Math.max(...numArr); // return large num for(var item in json){ if(json[item]==lagLen)lagStr=item; } console.log(lagLen)