padLeft

String.prototype.padLeft = function(len, c) {
    var s = this, c = c || '0';
    while (s.length < len) s = c + s;
    return s;
};
Example:
"123".padLeft(6, '0');

Result: 000123

Description

Adding char left of string.

Details

Double click on the code to select all.

 

;