Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

String.prototype.trim = function() {
    return this.replace(/(^\s+)|(\s+$)/g, "");
}

Related

  1. trim()
    String.prototype.trim = function() {
      var str = this.replace(/^\s\s*/, ''),
          ws  = /\s/,
          i   = str.length;
      while (ws.test(str.charAt(--i)));
      return str.slice(0, i + 1);
    };
    
  2. trim()
    String.prototype.trim = function() {
      return this.replace(/^\s*/, "").replace(/\s*$/, "");
    };
    
  3. trim()
    String.prototype.trim=function()
      return this.replace(/(\s*$)|(^\s*)/g, "");
    
  4. trim()
    String.prototype.trim = function()
        return this.replace(/^\s+/g, '').replace(/\s+$/g, '');
    };
    
  5. trim()
    String.prototype.trim = function() {
      var str = this.replace(/^\s+/, '');
      for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
          str = str.substring(0, i + 1);
          break;
      return str;
    ...
    
  6. trim()
    String.prototype.trim = function() {
      a = this.replace(/^\s+/, '');
      return a.replace(/\s+$/, '');
    };
    
  7. trim()
    String.prototype.trim = function () {
      "use strict";
      return this.replace(/^\s+|\s+$/g, '');
    };
    
  8. trim()
    String.prototype.trim = function() {
      var re = /^\s+|\s+$/g;
      return this.replace(re, "");
    
  9. trim()
    String._trimRE = new RegExp().compile(/^\s+|\s+$/g);
    String.prototype.trim = function()
      return this.replace(String._trimRE, "");