Js deletes an array instance by specifying a subscript or an element. js subscript

Source: Internet
Author: User

Js deletes an array instance by specifying a subscript or an element. js subscript

Example:

Deletes the Array element Array of the specified subscript. prototype. del = 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 ;}; Delete the specified element 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) ;}}; function a () {var arr = [1, 2, 3, 4, 5]; alert (arr. toString (); arr. remove (3); alert (arr. toString ());}

Method 1

Arr. del (0 );

The above is all the content of the js instance that deletes an array by specifying a subscript or a specified element ~

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.