Simplest inline method to left pad a string [duplicate]

Found a simple one line solution:

("0000" + n).slice(-4)

If the string and padding are in variables, you would have:

mystr="45"
pad = '0000'
(pad + mystr).slice(-pad.length)

Answer found here, thanks to @dani-p.
Credits to @profitehlolz.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)