JS in Split usage
- <script language="JavaScript" >
- function Spli () {
- datastr="2,2,3,5,6,6";
- var str= new Array ();
- Str=datastr.split (",");
- For (i=0;i<str.length; i++)
- {
- document.write (str[i]+"<br/>");
- }
- }
- Spli ();
- </script>
JS Delete array elements
var arr=[' A ', ' B ', ' C '];
To remove the ' B ', there are two ways:
1.delete method: Delete Arr[1]
This way the array length is not changed, at this point arr[1] becomes undefined, but also has the benefit of the original array index also remains unchanged, at this time to repeat the group elements can be used
For (index in ARR)
document.write (' arr[' +index+ ']= ' +arr[index]);
This traversal way skips the elements of undefined
* This method IE4.O support after all.
2. Array Object Splice method: Arr.splice (n);
This way the array length changes accordingly, but the original array index also changes accordingly
The first 1 in the splice parameter is the starting index of the deletion (from 0), where the second element of the array
The second 1, is to delete the number of elements, here only one element, that is, ' B ';
Traversing an array element can be used to iterate through an array, such as for, because the deleted element
The array does not retain
* This method is only supported after IE5.5
It is worth mentioning that the splice method can also add elements to an array while deleting an array element
For example, Arr.splice (' d ', ' e '), d,e two elements are added to the array arr.
The resulting array becomes arr: ' A ', ' d ', ' e ', ' C '
The split usage in JS and the deletion of elements in the array