Nodejs String Trim trim()

Here you can find the source of trim()

Method Source Code

// Example: Augmenting Types
// JavaScript allows us to augment the basic types of the language.

console.log("'" + " a ".trim() + "'");

String.prototype.trim = function(){
   return this.replace(/^\s+|\s+$/g, '');
};    //from w ww.j a v  a2s  .  co m

console.log("'" + " b ".trim() + "'");

// Because of the dynamic nature of JavaScript's prototypal inheritance, all 
// objects/values are imediatly endowed with the new methods, even objects/values
// that where created before the new methods where created.

Related

  1. trim()
    String.prototype.trim = function() {
      a = this.replace(/^\s+/, '');
      return a.replace(/\s+$/, '');
    };
    
  2. trim()
    String.prototype.trim = function () {
      "use strict";
      return this.replace(/^\s+|\s+$/g, '');
    };
    
  3. trim()
    String.prototype.trim = function() {
      var re = /^\s+|\s+$/g;
      return this.replace(re, "");
    
  4. trim()
    String._trimRE = new RegExp().compile(/^\s+|\s+$/g);
    String.prototype.trim = function()
      return this.replace(String._trimRE, "");
    
  5. trim()
    String.prototype.trim = function() {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    };
    
  6. trim()
    String.prototype.trim = function()
      var x=this;
      x=x.replace(/^\s*(.*)/, "$1");
      x=x.replace(/(.*?)\s*$/, "$1");
      return x;
    
  7. trim()
    var Firefox = (document.getElementById && !document.all);
    var MSIE = (-1 != navigator.userAgent.indexOf('MSIE'));
    String.prototype.trim=function(){
      return this.replace(/^\s+|\s+$/g,"");
    };
    function Redirect(url)
      parent.location=url;
    var Submitted = 0;
    function OnSubmit(form)
      if (Submitted) {
        return false;
      Submitted = 1;
      return true;
    
  8. trim()
    String.prototype.trim = function(){ 
      return this.rTrim(this.lTrim());
    
  9. trim()
    String.prototype.trim = String.prototype.trim || function () {
      const
        str = this.replace(/^\s\s*/, '');
      let
        i = str.length;
      for (let rgxp = /\s/; rgxp.test(str.charAt(--i));) {
      return str.substring(0, i + 1);
    };
    ...