String Operators

String repetition operator in Javascript

Javascript seems to be missing a String repetition operator like 'x' in Perl.

It's a pity because the Perl way

var message = "I am a fish " x 80;

is much more concise than the Javascript way:

function StringRepeat(s,count) { for (var r="",i=0; i<count; i++) {r+=s;} return r;}
var message = StringRepeat("I am a fish ",80);

Or am I missing something? --Hamstersoup 03:33, 3 March 2007 (PST)

No, you're not missing anything. It's not there, for whatever reason. --Waldo 19:03, 3 March 2007 (PST)

Here is a concise way to do this in JavaScript, as suggested inย Repetition Operator in JavaScript

var message = new Array(81).join("I am a fish ");