ExtensionMethod.NET Home of 877 C#, Visual Basic, F# and Javascript extension methods

padLeft

Adding char left of string.

Source

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

Author: Mustafa Gülmez

Submitted on: 19 jun. 2013

Language: JavaScript

Type: String

Views: 6007