Pad functions for Javascript

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;
};

Please rate this snippet

IndexOf method for Javascript

With the snippet below you can use the IndexOf method for Javascript.

Sample JS

Array.prototype.IndexOf = Array.prototype.IndexOf || function (element) {
    for (var i=0; i < this.length; i++) {
        if(this[i] === element) return i;
    }
    return -1;
};

Please rate this snippet