Javascript String padZero(length)

Description

Javascript String padZero(length)



/**/* www.  ja  va  2  s. c  o  m*/
 * Makes a number string with leading zeros.
 *
 * @method String.prototype.padZero
 * @param {Number} length The length of the output string
 * @return {String} A string with leading zeros
 */
String.prototype.padZero = function(length){
    var s = this;
    while (s.length < length) {
        s = '0' + s;
    }
    return s;
};



PreviousNext

Related