EDIT:
Completely forgot that ES6 will also have a String.prototype.repeat method:
var s = "1".repeat(6);
This is available right now in Firefox, but a patch is needed for older browsers.
Original answer:
ECMAScript 6 will have a Array.prototype.fill method.
var s = Array(6).fill("1").join("");
You can use it now with a compatibility patch.
Something like this should be close, though perhaps not entirely compatible:
if (!Array.prototype.fill) {
Array.prototype.fill = function(val, start, end) {
start = parseInt(start)
start = isNaN(start) ? 0 :
start < 0 ? Math.max(this.length + start, 0) :
Math.min(this.length, start)
end = parseInt(end)
end = isNaN(end) ? this.length :
end < 0 ? Math.max(this.length + end, 0) :
Math.min(this.length, end)
while (start < end)
this[start++] = val
return this
}
}
forloop