3

TypeScript String repeat() Method

 1 month ago
source link: https://www.geeksforgeeks.org/typescript-string-repeat-method/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

TypeScript String repeat() Method

Last Updated : 27 Feb, 2024

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.

  • Javascript
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.

  • Javascript
const numString: String = "12345";
const repeatedNumString: String =
numString.repeat(2);
console.log(repeatedNumString);

Output:

“This course was packed with amazing and well-organized content! The project-based approach of this course made it even better to understand concepts faster. Also the instructor in the live classes is really good and knowledgeable.”- Tejas | Deutsche Bank

With our revamped Full Stack Development Program: master Node.js and React that enables you to create dynamic web applications.

So get ready for salary hike only with our Full Stack Development Course.

Like Article
Suggest improvement
Share your thoughts in the comments

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK