Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Padding numbers with leading 0
/**
padding numbers with leading 0
@param {String, Number} arg1, arg2 - arg1 padding string, arg2 length
@return {String} return padded string
*/
String.prototype.lpad = function(padString, length) {
var str = this;
while (str.length < length)
str = padString + str;
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment