Turn from: http://www.cnblogs.com/chiname/articles/216517.html (Invasion and deletion)
/*
* Method: Array.removeat (Index)
* Function: Delete array element.
* Parameter: Index deletes the subscript of the element.
* Return: Modify array on the original array
*/
Array.prototype.removeAt = function (index) { if (IsNaN (index) | | Index > This.length) { return false;} for (var i = 0, n = 0; i < this.length; i++) { if (this[i]! = This[index]) { this[n++] = this[i] } }
this.length-= 1}
/*
* Method: Array.remove (obj)
* Function: Delete array element.
* Parameters: The object to be deleted.
* Return: Modify array on the original array
*/
Array.prototype.remove = function (obj) { if (null = = obj) { return;} for (var i = 0, n = 0; i < this.length; i++) { if (this[i]! = obj) { this[n++] = this[i]; } } This.length-= 1}
/*
* Method: Array.contains (obj)
* Function: Determines whether an element is in an array.
* Parameters: Object to find
* Return: Found to return true, otherwise return false;
*/
Array.prototype.Contains = function (obj) { if (null = = obj) { return;} for (var i = 0, n = 0; i < this.length; i++) { if (this[i]! = obj) { return true; } } return false; }
/*
* Method: Array.indexof (obj)
* Function: Searches for the specified object and returns the zero-based index of the first occurrence
* Parameters: Object to find
* Return: Find the index that returns the element in the array, otherwise return-1
*/
Array.prototype.IndexOf = function (obj) { if (null = = obj) { return;} { for (var i = 0, n = 0; i < this.length; i++) { if (this[i] = = obj) { return i; }} } return-1; }
/*
* Method: Array.clear ()
* Function: Empty array element.
* Parameter: None.
* Return: Empty array
*/
Array.prototype.Clear = function () { this.length = 0;}
/*
* Method: Array.formatstring ()
* Function: Returns the array position.
* Parameter: None.
* Return: string
*/
Array.prototype.formatString = function () { var str = '; for (var i = 0; i < this.length; i++) { if (i = = this.length-1) { str + = This[i]; } else { str + = this[i] + '; '; } } return str;};
JS in prototype use (array)