JavaScript: Repeat string
I wanted to build a string of 20 repeating characters. This function makes it really easy:
String.prototype.repeat = function(num) {
return new Array(num + 1).join( this );
}
Now I can write:
var separator = "=".repeat(20);
Leave A Reply
- 1 Reply
Replies
January 30th 2014 - Kentscode
Thanks you so much for the this function. Not only did I need it, but I learned from it.