Javascript String pad(len, str, left)

Description

Javascript String pad(len, str, left)


String.prototype.pad = function(len, str, left) {
    var res = this,
        tmp = str || ' ';
    if (left === true) {
        while (res.length < len) res = tmp + res;
    }//  ww  w . j ava 2 s. c  o m
    else {
        while (res.length < len) res += tmp;
    }
    return res;
};



PreviousNext

Related