JavaScript zero-pad using array 

Joined:
02/21/2009
Posts:
158

March 03, 2011 21:48:52    Last update: March 03, 2011 21:48:52
Just another way to left zero-pad a string.
function zeroPad(s, length) {
    if (s.length >= length) {
        return s;
    }
    var a = [];
    a[length-s.length] = s;
    return a.join('0');
}
Share |
| Comment  | Tags