String split based on repetitions - Javascript String

Javascript examples for String:split

Description

String split based on repetitions

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  ww w. j a  v a 2  s  . com
var str = '111122331234444455555';
var strObj = {};
for(var i = 0; i < str.length; i++){
     if(strObj[str[i]]) {
         strObj[str[i]]+=str[i];
     } else {
        strObj[str[i]] = str[i];
     }
}
for (var key in strObj) {
  if (strObj.hasOwnProperty(key)) {
    console.log(key + " -> " + strObj[key]);
  }
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials