Skip to content

Pad Javascript String With A Character

Jason Lewis edited this page Jan 4, 2021 · 1 revision
  • On new browsers simple use the .padStart method of the string object.
    myString.padStart(4, '0')

This will pad myString with 0s to a length of 4. E.G.
'24' => '0024'

Clone this wiki locally