Skip to content

Instantly share code, notes, and snippets.

@dehghani-mehdi
Created July 4, 2017 08:16
Show Gist options
  • Save dehghani-mehdi/a6c77fee105e9449570fa14d1b5a7417 to your computer and use it in GitHub Desktop.
Save dehghani-mehdi/a6c77fee105e9449570fa14d1b5a7417 to your computer and use it in GitHub Desktop.
C# like trimStart method in JavaScript
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