Nodejs String Trimming Right trimEnd(c)

Here you can find the source of trimEnd(c)

Method Source Code

String.prototype.trimEnd=function(c)
{
    c = c?c:' ';/*from   w w w. j  a va 2s.c  om*/
    var i=this.length-1;
    for(;i>=0 && this.charAt(i)==c;i--);
    return this.substring(0,i+1);
}

var Utils = {
    getValues : function(dataSet)
    {
        var res = [];
        for(var key in dataSet) {
            res.push(dataSet[key]);
        }
        return res;
    }
};

Related

  1. rtrim()
    String.prototype.rtrim = function(){
        var res = this;
        while (res.substring(res.length - 1, res.length) == " ") {
            res = res.substring(0, res.length - 1);
        return res;
    
  2. rtrim()
    String.prototype.rtrim=function()
      {return this.replace(/\s+$/,'');}
    
  3. rtrim(ch)
    String.prototype.rtrim = function(ch) {
        var r = new RegExp("{0}+$".format(ch || "\\s"))
        return this.replace(r, "");
    };
    
  4. rtrim(charlist)
    String.prototype.rtrim = function (charlist) {
      charlist = !charlist ? ' \\s\u00A0' : (charlist + '').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
      var re = new RegExp('^[' + charlist + ']+', 'g');
      return this.replace(re, '');
    };
    
  5. trimEnd()
    String.prototype.trimEnd = function() {
      for (var i=this.length-1; this.charAt(i) ==' '; i--) {
        this.substring(0, i);
      return this;
    };
    
  6. trimEnd(c)
    String.prototype.trimEnd=function(c)
        c = c?c:' ';
        var i=this.length-1;
        for(;i>=0 && this.charAt(i)==c;i--);
        return this.substring(0,i+1);
    
  7. trimEnd(s)
    String.prototype.trimEnd = function(s) {
        return this.replace(new RegExp(s + "+$", "gm"), "")
    
  8. trimEnd(trimStr)
    String.prototype.trimEnd = function (trimStr) {
        if (!trimStr) {
            return this;
        var temp = this;
        while (true) {
            if (temp.substr(temp.length - trimStr.length, trimStr.length) != trimStr) {
                break;
            temp = temp.substr(0, temp.length - trimStr.length);
        return temp;
    
  9. trimRight()
    String.prototype.trimRight = String.prototype.trimRight || function() {
      return this.replace(/\s+$/,'');
    };