Linked Questions

890 votes
24 answers
434k views

In Perl I can repeat a character multiple times using the syntax: $a = "a" x 10; // results in "aaaaaaaaaa" Is there a simple way to accomplish this in Javascript? I can obviously use a function, but ...
Steve's user avatar
  • 55.8k
43 votes
5 answers
50k views

I'm writing JavaScript unit tests and I need to create a string of length 65536. What's the best way to do this in JavaScript? Currently I'm using: var myString = ''; for (var i = 0; i <= 65535; +...
Victor L's user avatar
  • 10.3k
20 votes
5 answers
32k views

In JavaScript, how would I create a string of repeating strings x number of times: var s = new String("&nbsp;",3); //s would now be "&nbsp;&nbsp;&nbsp;"
BrokeMyLegBiking's user avatar
3 votes
5 answers
8k views

Is there any simple way to multiply alphanumeric string in jQuery / JS? e.g var str = "ABC"; console.log( str * 5 ); // this will nerutn `Nan` // where what i want is `ABCABCABCABCABC` Any ...
Iladarsda's user avatar
  • 10.7k
1 vote
4 answers
1k views

Possible Duplicate: Repeat String - Javascript 'h' x n; Here n is a variable, and the generated string should be n times duplicate of h: hh..h( n occurance of h in all)
new_perl's user avatar
  • 7,815
-3 votes
2 answers
2k views

I am trying to figure out how to make a simple function that will take 2 arguments and return a new string that will repeat the string a certain amount of times that is described in the 2nd argument. ...
Chuck D's user avatar
2 votes
3 answers
150 views

I need to understand how Javascript handles the new string object just like in the C# code below var UpperBound = 14; for (int i = 0; i < UpperBound; i++) { Console.WriteLine(new string('*', i)...
fokosun's user avatar
  • 546
-1 votes
2 answers
552 views

#Python Code characters = "Hello World!" print(characters * 4) #it Will Print Hello World! 4 times // Javascript Code characters = "Hello World!" console.log(characters * 4)
Pradeep Saravanan's user avatar
0 votes
1 answer
561 views

I have been looking for a while for this answer and most results bring up people NOT wanting to push more than once, and its hard to find a straight forward solution / alternative. I have been ...
Tom TK's user avatar
  • 65
2 votes
1 answer
290 views

I have a char ('-') and a number (80) of times it should be repeated in a string. I need to get a string of that char repeated given number of times: --------------------------------------------------...
Trident D'Gao's user avatar
-1 votes
1 answer
216 views

so I am very new to js and I'm having a really hard time comprehending the language. Could anyone take 5 to look at this code and tell me why my function isn't working...? The goal is to create a ...
Kaiden Ashun's user avatar
0 votes
1 answer
36 views

I'f you're familiar with Python, I'm sure you're aware that you can multiply a String by an Integer to get that desired amount of Strings back. Example: 'J' * 3 --> 'JJJ' What's the most ...
user avatar
1 vote
0 answers
32 views

Here is an interesting question, in javascript what is the best way to convert a positive integer into a string of multiple zeros? For example 3 will be convertd to '000', 7 will be converted to '...
Xavier_Ex's user avatar
  • 8,826
1 vote
0 answers
21 views

In python to get an array of X strings (repeated) I can do: >>> 'hi' * 3 # 'hihihi' Perhaps 'array' isn't the correct term but hopefully the above example clarifies what I mean. Is there a ...
samuelbrody1249's user avatar
3551 votes
32 answers
2.0m views

How can I display JSON in an easy-to-read (for human readers) format? I'm looking primarily for indentation and whitespace, with perhaps even colors / font-styles / etc.
Mark's user avatar
  • 70.5k

15 30 50 per page