This snippet will give you the pad functions (padRight, padLeft) for javascript.

Sample Javascript

String.prototype.padLeft = function(length, character) {
	var text = this.valueOf();
	var character = character || " ";
	while (text.length<length) {
		text = character + text;
	}
	return text;
};

String.prototype.padRight = function(length, character) {
	var text = this.valueOf();
	var character = character || " ";
	while (text.length<length) {
		text = text + character;
	}
	return text;
};

2 thought on “Pad functions for Javascript”

Leave a Reply