String object extensions: pad from left - Node.js String

Node.js examples for String:Padding

Description

String object extensions: pad from left

Demo Code


String.prototype.pad_left = function(pad_length, pad_string) {
    var new_string = this;
    for (var i = 0; new_string.length < pad_length; i++) {
        new_string = pad_string + new_string;
    }/*from  ww w. j av a  2 s  .  c o m*/
    return new_string;
}

Related Tutorials