Javascript String trim() method

Description

Javascript String trim() method



String.prototype.trim =  function() {
    if (!this) return this;

    return this.replace(/\s+/g,"");
};

Javascript String trim()


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

Javascript String trim()



String.prototype.trim = (function() {

  var trimRegex = /(^\s+|\s+$)/g;

  return function() {
    return this.replace(trimRegex, '');
  };//from   www. j a v  a2s  . c  om

}());

Javascript String trim()


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



PreviousNext

Related