Trim String Prototype


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. String.prototype.trim = function() {
  2. // skip leading and trailing whitespace
  3. // and return everything in between
  4. var trimmedString = this;
  5. trimmedString = trimmedString.replace(/^\s+/,"");
  6. trimmedString = trimmedString.replace(/\s+$/,"");
  7. return trimmedString;
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.