Skip to content

padStart

The padStart() method pads the current string with a given string to reach a fixed length. The padding is applied at the start of the current string.

Interactive example

Syntax

Classic signature

typescript
function padStart<
	GenericInput extends string
>(
	input: GenericInput,
	targetLength: number,
	padString: string
): string

Curried signature

typescript
function padStart<
	GenericInput extends string
>(
	targetLength: number,
	padString: string
): (input: GenericInput) => string

Parameters

  • input: The string to pad.
  • targetLength: The length of the resulting string once padded.
  • padString: The string to use to pad the current string.

Return value

A new string of the specified length, padded with the provided string from the start.

See also

  • padEnd - Pads the string at the end
  • repeat - Repeats a string a given number of times

Sources

Released under the MIT license.