Add methods for Arrays array objects

The prototype property gives you the ability to add properties and methods to an object.

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

Array.prototype.remove = function(val) {
	var index = this.indexOf(val);
	if (index > -1) {
	this.splice(index, 1);
	}
};

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325963671&siteId=291194637