Javascript String padRight(count, character)

Description

Javascript String padRight(count, character)



String.prototype.padRight = function(count, character) {
    var result = "";

    count -= this.length;//  ww  w  .ja  va2 s .  co m

    if (count <= 0) {
        return this.toString();
    }
    if (character === undefined) {
        character = " ";
    }

    var i;
    for (i = 0; i < count; i += 1) {
        result += character;
    }

    return String(this)+result;
};



PreviousNext

Related