Skip to content

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
See also  Java Abstract Class - Hackerrank Challenge - Java Solution

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.