DEV Community

Poopcoder
Poopcoder

Posted on • Originally published at poopcode.com on

How to create copies of a string in JavaScript?

To create copies of a string in JavaScript, we can use String.prototype.repeat() method. It takes a number as an argument and repeats the string n times and returns it.

let str = "poopcode";

console.log(str.repeat(2)); //poopcodepoopcode

console.log(str.repeat(5)); //poopcodepoopcodepoopcodepoopcodepoopcode
Enter fullscreen mode Exit fullscreen mode

Top comments (0)