How to use repeat in Javascript

By FoxLearn 9/5/2024 8:31:30 AM   57
In JavaScript, if you want to repeat a string multiple times, you can use the repeat() method available on strings.

The repeat() method in JavaScript is used to create a new string that consists of a specified number of copies of the original string, concatenated together.

For example:

const str = 'Javascript';
const repeatedStr = str.repeat(3); // Repeats the string 3 times
console.log(repeatedStr); // Output: 'JavascriptJavascriptJavascript'

This method is straightforward and efficient for creating repeated string patterns without needing manual concatenation in loops.