JS Utils Kit - v0.5.1
    Preparing search index...

    Function padLeft

    • Pads a string on the left with a specified character until it reaches the desired length.

      Parameters

      • str: string

        The string to pad.

      • length: number

        The target length of the padded string.

      • char: string = ' '

        The character to use for padding (defaults to a space).

      Returns string

      The padded string, or the original string if its length is already greater than or equal to the target length.

      console.log(padLeft("hello", 8)); // "   hello"
      console.log(padLeft("hi", 5, "*")); // "***hi"
      console.log(padLeft("hello", 3)); // "hello"
      console.log(padLeft("", 3, "0")); // "000"