Created
July 4, 2017 08:16
-
-
Save dehghani-mehdi/a6c77fee105e9449570fa14d1b5a7417 to your computer and use it in GitHub Desktop.
C# like trimStart method in JavaScript
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
String.prototype.trimStart = function(c) { | |
if (this.length == 0) return this; | |
c = c ? c : ' '; | |
var i = 0; | |
for (; i < this.length && this.charAt(i) == c; i++); | |
return this.substring(i); | |
} | |
// Example | |
" hello world!".trimStart(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment