-1

How to create a string from one char with JavaScript?

This is C#.

String text = new String('*',20);

Is there an easy way to do this with JavaScript?

2
  • If that's a JavaScript question, please state the goal, not a code you want ported from another language. Commented May 9, 2014 at 15:02
  • From his given example, he wants an easy code in JS that creates a string "********************" Commented May 9, 2014 at 15:04

1 Answer 1

6

You could join an array

var text = new Array(20).join('*');

// returns ********************
Sign up to request clarification or add additional context in comments.

2 Comments

@rlemon +1 for confusing SO with reddit
@MBottens no confusion. people on Reddit are nicer :P

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.