Is there way of generating a string made up of 250 underscores, without using a loop?
I want to avoid writing code like this:
var myString= '';
for (var i=0; i < 250; i++) {
myString += '_';
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no built-in solution but the question Repeat String – Javascript has a nice solution:
If you don’t want to alter the String prototype you can just do:
This is creating an array of 251 undefineds an then joining them by your character.
Since undefined is ” (empty string) when converted to a string in
.join(), this gives you the string you’re after.