Javascript String pad(len, str)

Description

Javascript String pad(len, str)


/**/* ww w .  j av a  2 s .  c  om*/
 * Pads a String with the supplied str parameter,
 * to the length defined as len.
 * @param len
 * @param str
 * @return String
 */
String.prototype.pad = function(len, str){

    var output = this.valueOf();

    while(output.length < len){
        output = str + output;
    }

    return output;
};



PreviousNext

Related