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
Top comments (0)