TypeScript String repeat() Method
In TypeScript the repeat() method helps in generating a new string by replicating the original string up to a certain number of iterations. It's an inbuilt method of TypeScript as well as JavaScript.
Syntax
string.repeat(count: number): string;
Parameters:
- count: No. of times you want to repeat the string.
Return Value:
A new string consisting of the original string repeated count times.
Example 1: To demonstrate creating a string by repetition of a string using repeat() method.
const geek: String = "GeeksForGeeks";
const repeatedGeek: String =
geek.repeat(3);
console.log(repeatedGeek);
Output:
GeeksForGeeksGeeksForGeeksGeeksForGeeks
Example 2: To demonsrating creating a String by repetition of a string.
const numString: String = "12345";
const repeatedNumString: String =
numString.repeat(2);
console.log(repeatedNumString);
Output:
1234512345