Linked Questions
40 questions linked to/from Repeat String - Javascript
890
votes
24
answers
434k
views
Repeat a string in JavaScript a number of times
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 ...
43
votes
5
answers
50k
views
How to create a string with n characters? How to create a string with specific length? [duplicate]
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; +...
20
votes
5
answers
32k
views
How can I repeat strings in JavaScript? [duplicate]
In JavaScript, how would I create a string of repeating strings x number of times:
var s = new String(" ",3);
//s would now be " "
3
votes
5
answers
8k
views
jQuery - multiplying alphanumeric string [duplicate]
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 ...
1
vote
4
answers
1k
views
How do I generate 'h' x n in javascript? [duplicate]
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)
-3
votes
2
answers
2k
views
Function Repeater JavaScript [duplicate]
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.
...
2
votes
3
answers
150
views
how to convert this C# code snippet to Javascript [duplicate]
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)...
-1
votes
2
answers
552
views
How can I multiple Strings with Integers in Javascript as in python, if we cant what's the reason and is there any other way to do so? [duplicate]
#Python Code
characters = "Hello World!"
print(characters * 4) #it Will Print Hello World! 4 times
// Javascript Code
characters = "Hello World!"
console.log(characters * 4)
0
votes
1
answer
561
views
How to make array.push() a string multiplied by i [duplicate]
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 ...
2
votes
1
answer
290
views
What is the most efficient way to create an N-times-a-character string in JavaScript? [duplicate]
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:
--------------------------------------------------...
-1
votes
1
answer
216
views
How to create a repeatString Function [duplicate]
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 ...
0
votes
1
answer
36
views
Manipulating a String's content with an Integer [duplicate]
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 ...
1
vote
0
answers
32
views
Transform a positive integer into a string of multiple zeros [duplicate]
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 '...
1
vote
0
answers
21
views
Multiply a string by itself in javascript [duplicate]
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 ...
3551
votes
32
answers
2.0m
views
pretty-print JSON using JavaScript
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.