To delete an array-specified subscript:
| The code is as follows |
Copy Code |
HTML code<script> var arr = [' A ', ' B ', ' C ', ' d ', ' e ']; function Arr_del (d) { Return Arr.slice (0,d-1). Concat (Arr.slice (d)); } Alert (Arr_del (3)); A,b,d,e </script> |
/*
* Deletes an array to specify an element for the subscript.
*/
| The code is as follows |
Copy Code |
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 } |
/*
* Gets the element index of the specified value in the array
*/
| The code is as follows |
Copy Code |
Array.prototype.getArrayIndex = function (value) { var index =-1; for (var i = 0; I < this.length; i++) { if (this[i] = = value) { index = i; Break } } return index; } |
Common functions for arrays
ToString (): Converts an array to a string
toLocaleString (): Converts an array to a string
Join (): Converts an array into a symbolic concatenated string
Shift (): Moves an element of an array's head out
Unshift (): Inserts an element in the header of an array
Pop (): Deletes an element from the tail of an array
Push (): Adds an element to the tail of the array
Concat (): Adding elements to an array
Slice (): Returns the part of an array
Reverse (): Sort the array in reverse order
Sort (): Sorting operations on array
Splice (): Inserts, deletes, or replaces an array element