ExtensionMethod.NET Home of 875 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: 5911