Javascript String padLeft(count, character)

Description

Javascript String padLeft(count, character)



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

    count -= this.length;//from w  w w.  ja  v  a  2s . c  o  m

    if (count <= 0) {
        return String(this);
    }

    if (character === undefined) {
        character = " ";
    }

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

    return result+this;
};



PreviousNext

Related