Skip to content

Instantly share code, notes, and snippets.

@argshook
Created November 14, 2013 13:23
Show Gist options
  • Save argshook/7466710 to your computer and use it in GitHub Desktop.
Save argshook/7466710 to your computer and use it in GitHub Desktop.
Repeat string as many times as you need without any loops.
String.prototype.repeat = function(times) {
return (new Array(times + 1)).join(this);
};
var str = "1".repeat(3);
console.log(str); // 111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment