JS in prototype use (array)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.