Efficient way to create an N-times-a-character string - Javascript String Operation

Javascript examples for String Operation:String Convert

Description

Efficient way to create an N-times-a-character string

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(){/*from ww  w.  ja v  a 2  s  .  c o  m*/
String.prototype.repeat = function (len) {
    return (new Array(len + 1)).join(this);
}
console.log('-/'.repeat(5));
    }

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

Related Tutorials