Skip to content

Instantly share code, notes, and snippets.

@dehghani-mehdi
Created July 4, 2017 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dehghani-mehdi/4868c5f70e5604c7362b0c9c58f304c2 to your computer and use it in GitHub Desktop.
Save dehghani-mehdi/4868c5f70e5604c7362b0c9c58f304c2 to your computer and use it in GitHub Desktop.
C# like trimEnd method in JavaScript
String.prototype.trimEnd = function(c) {
if (this.length == 0) return this;
c = c ? c : ' ';
var i = this.length - 1;
for (; i >= 0 && this.charAt(i) == c; i--);
return this.substring(0, i + 1);
}
// Example
"hello world! ".trimEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment