(Www.bkjia.com) Tutorial Javascript custom array deletion method remove ()
Copy to ClipboardReference: [www.bkjia.com] <Head>
<Title> Javascript custom array deletion method remove () </title>
<Script type = "text/javascript">
Array. prototype. remove = function (dx ){
If (isNaN (dx) | dx> this. length) {return false ;}
For (var I = 0, n = 0; I <this. length; I ++ ){
If (this [I]! = This [dx]) {
This [n ++] = this [I]
}
}
This. length-= 1
}
Function f (){
Var str = "001 | 002 | 003 ";//
Var arr = str. split ("| ");
Alert ("length of the array before deletion:" + arr. length );
For (var I = 0; I <arr. length; I ++ ){
Alert (arr [I]);
}
Arr. remove (1); // javascript does not contain functions.
Alert ("length of the deleted array:" + arr. length );
For (var I = 0; I <arr. length; I ++ ){
Alert (arr [I]);
}
}
</Script>
</Head>
<Body>
<Input type = "button" onclick = "f ();" value = "OK"/>
</Body>
</Html>