Skip to content

Instantly share code, notes, and snippets.

@githubnando
Created June 28, 2017 19:10
Show Gist options
  • Save githubnando/94d8d301bbac78b609a162459de6fb7d to your computer and use it in GitHub Desktop.
Save githubnando/94d8d301bbac78b609a162459de6fb7d to your computer and use it in GitHub Desktop.
Pad left a string with a given number of characters
strPadLeft(string, length, char) {
const str = '' + string;
let pad = '';
for (let i = 0; i < length; i++) {
pad += char;
}
return pad.substring(0, pad.length - str.length) + str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment