The repeat()
method in TypeScript is used to return a new string a repeated number of times. This method is similar to JavaScript repeat()
method. This is because anywhere that JavaScript runs, TypeScript runs too.
string.repeat(n)
string
: This is the string we want to return a number of times.
n
: This represents how many times we want to return the specified string.
The value returned is a copy or copies of the number specified an n
number of times.
// create stringslet string1:string = "Edpresso"let string2:string = "Is"let string3:string = "The"let string4:string = "Best!"// print copies of this strings for some number of timesconsole.log(string1.repeat(4))console.log(string2.repeat(3))console.log(string3.repeat(2))console.log(string4.repeat(1))
repeat()
method.