Created
June 28, 2017 19:10
-
-
Save githubnando/94d8d301bbac78b609a162459de6fb7d to your computer and use it in GitHub Desktop.
Pad left a string with a given number of characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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