Skip to content

Instantly share code, notes, and snippets.

@peterjwest
Last active August 29, 2015 14:02
Show Gist options
  • Save peterjwest/90957f491aaed305ac10 to your computer and use it in GitHub Desktop.
Save peterjwest/90957f491aaed305ac10 to your computer and use it in GitHub Desktop.
Left pad a string in javascript
var pad = function(string, length, char) {
return (new Array(length).join(char[0] || '0') + string).slice(-Math.max(string.toString().length, length));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment