Skip to content

repeat ​

The repeat() method returns a new string that is the original string repeated a specified number of times.

Interactive example ​

Syntax ​

Classic signature ​

typescript
function repeat<
	GenericInput extends string
>(
	input: GenericInput, 
	count: number
): string;

Curried signature ​

typescript
function repeat<
	GenericInput extends string
>(
	count: number
): (input: GenericInput) => string;

Parameters ​

  • input: The string to repeat.
  • count: The number of times the string must be repeated. Must be a non-negative integer. If count is 0, an empty string is returned.

Return value ​

A new string resulting from repeating the original string count times.

See also ​

  • normalize: Normalizes a string according to a specified Unicode form.
  • replace: Replaces occurrences in a string.
  • trim: Removes whitespace at the start and end of a string.

Sources ​

Released under the MIT license.