OneCompiler

[Javascript] How to repeat a string x number of times?

I want to repeat a string for a given number of times, How can I do that in Javascript?

1 Answer

4 years ago by

repeat() method is used to repeat a string for n number of times. For example,

let str = 'hello';
console.log(str.repeat(5));

Run here https://onecompiler.com/javascript/3xns34rrb

4 years ago by Meera